avoid toLower in std.algorithm.sort compare alias
Jay Norwood
jayn at prismnet.com
Sat Apr 21 18:47:30 PDT 2012
On Saturday, 21 April 2012 at 23:54:26 UTC, Jonathan M Davis
wrote:
> Yeah. toLower would be called on both strings on _every_
> compare. And since
> that involves a loop, that would make the overall call to sort
> an order of
> magnitude worse than if you didn't call toLower at all. I'm not
> sure if it's
> an order of magnitude worse than your solution though, since
> it's been a while
> since I studied Big(O) notation (doing the conversion only once
> is still more
> expensive than not converting, but I'm not sure how much more
> expensive - it
> might cost less than sort such that it actually doesn't matter
> as for as
> Big(O) goes though).
>
> - Jonathan M Davis
use of toLower in the sort expression adds around 11.2 secs
overhead to a 0.3 sec operation which reads and sorts the 34k
directory entries in this 2GB layout on the ssd drive, so it
isn't an option for me.
finished! time:312 ms
finished! time:11598 ms
std.algorithm.sort!("toLower(a) <
toLower(b)",std.algorithm.SwapStrategy.stable)(dirs);
//std.algorithm.sort!("a < b",
std.algorithm.SwapStrategy.stable)(dirs);
More information about the Digitalmars-d-learn
mailing list