|Think about Loose Coupling|
Re^7: Perl is dying (better sorting than the ST)by demerphq (Chancellor)
|on Feb 11, 2007 at 12:07 UTC||Need Help??|
Er, maybe im missing something here, how is an ST any different from what you have done in terms of big O. Leaving the sort aside since presumably it is as efficient either way, it appears to me that with an ST you have N steps to create the arrays, and N steps to unpack them, with your code you have N steps to create the key array, and N steps to map the sorted keys back to real values.
It strikes me that your routine might be more efficient because the unit cost of each step will be cheaper, but that seems to me to be a form of optimisation that could be argued should be left to the compiler.
So what am I missing?
Also, if you are going down this route you might as well go as far you can. According to benchmark the true GRT I whipped up for this is about 50% faster than your routine, and uses less memory (by two whole AV's :-).
Because the GRT avoids the substr, needs no indirection on the key which in turn means you dont need provide a custom sort function which in turn means the per cost of each comparison is quite a bit lower. AND you get the added bonus that the sort is stable, and a lower memory profile.
But it also arguable that this too is a form of premature optimisation.
Update: when i compare your approach to a ST like the following, i see no performance difference between it and your approach.