|Welcome to the Monastery|
Schwartzian Transform vs. plain Perlby Russ (Deacon)
|on Jun 08, 2000 at 15:10 UTC||Need Help??|
Russ has asked for the
wisdom of the Perl Monks concerning the following question:
Hopefully, this is an interesting question about the Schwartzian Transform and Perl internal performance:
I thought I was going to demonstrate the performance advantage of the Schwartzian Transform by applying it to the three-way sort code posted by BBQ. It is slower, however, with my quick implementation (which looks right...)
So, now it's once again my turn to learn (happens all the time around here -- I love Perl Monks)...
The Schwartzian Transform is all about reducing the computational difficulty of comparison code during complicated sorts. In this case, I assumed that two hash lookups, followed by two string length calculations, finally followed by a plain comparison would easily qualify as a "complicated" sort block.
What's happening, here? Why does it take longer to dereference and index into an array than to do hash lookups and length() calls?
P.S. My omitted data had all of the values equal (to force the comparison to always do the most work). It is just generated with map(($_, 1), (1..10000)).