avoid toLower in std.algorithm.sort compare alias
bearophile
bearophileHUGS at lycos.com
Sat Apr 21 17:36:18 PDT 2012
Jonathan M Davis:
> 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).
Performing the toLower every time the cmp function is called doesn't change the O complexity. In Phobos there is an alternative sorting (Schwartzian sorting routime) that applies a function to each item before sorting them, usually is much slower than the normal sorting, but maybe this time it's convenient.
The performance improvement in the OP message is large, maybe it's a problem of memory allocations of the converted strings... More info on the original code is needed to give better answers.
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list