commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gilles <gil...@harfang.homelinux.org>
Subject Re: [math] Add Pair factory method, toString(), Comparator
Date Wed, 16 Oct 2013 20:56:06 GMT
On Wed, 16 Oct 2013 09:57:52 +0100, Sean Owen wrote:
> On Wed, Oct 16, 2013 at 9:52 AM, Gilles 
> <gilles@harfang.homelinux.org>wrote:
>
>>  I think the Comparator can also replace a
>>> custom one in MathArrays.
>>>
>>
>> Are you sure?
>>
>
> Yes, at least tests pass. There are two anonymous comparator classes 
> there
> which compare by key. The new Comparator compares by key too (and by 
> value,
> but this shouldn't hurt as the current code doesn't care about 
> ordering
> among pairs with the same key). Collections.reverseOrder() can be 
> used to
> reverse the Comparator too.

The potential problem is performance. The current code for 
"sortInPlace" is
not as fast as it could be, very probably because it uses a Comparator. 
IIUC,
using your new comparator will add another "if" (to test whether 
comparing the
"value"s is necessary). [And "reverseOrder" will also add a few 
operations on
its own, I guess.]
It would be nice to know whether the impact is really fairly 
negligible, or
not.

There is a class (in the "test" part of repository) for performing 
simple
benchmarks:
   org.apache.commons.math3.PerfTestUtils
that tries to provide fair comparison results by interleaving calls to 
two
(or more) alternative codes.


Best regards,
Gilles


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message