Don't ask to ask, just ask | |
PerlMonks |
Re: Re: Advanced Sorting - GRT - Guttman Rosler Transformby demerphq (Chancellor) |
on Aug 10, 2003 at 13:07 UTC ( [id://282607]=note: print w/replies, xml ) | Need Help?? |
Your benchmark is utterly bogus. First, you use the q{} form of benchmark and yet you try to access a lexical variable that will not be in scope when the code is evaled. So your code benchmarks sorting an empty list! (The counts in the millions per second range should have tipped you off that something was wrong.) Next the 'st' implementation has a bug in it so it doesnt actually sort correctly $a->[0] <=> $a->[0] should read $a->[0] <=> $b->[0], and the 'bare' implementation doesnt do the full sort either as it doesnt sort based on the word as well as the 'E' count. Once the benchmark is fixed up to actually test similar things against similar things, and to use a better non empty data set we see that the GRT crushes the competition, and that the ST greatly outperforms the uncached code.
And using the exact same data set as you did we see that the GRT still wins, even if 'bare' outperforms 'st'.
The moral of the story is a common one: Always test your benchmarks. Always double check that what you are comparing is equivelent. Always be careful with selecting the data set you benchmark against. If you benchmark a code snippet and not a subref then you should excercise even more caution. (Generally I dont think its a good idea actually.) --- demerphq <Elian> And I do take a kind of perverse pleasure in having an OO assembly language...
In Section
Meditations
|
|