Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^4: Benchmark, -s versus schwartzian (vs hash)

by Aristotle (Chancellor)
on Aug 23, 2004 at 11:04 UTC ( #385050=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Benchmark, -s versus schwartzian (vs hash)
in thread Benchmark, -s versus schwartzian

That "strange" approach is generally faster. See Re^2: When the Best Solution Isn't and Re: To use a module...or not.

Makeshifts last the longest.


Comment on Re^4: Benchmark, -s versus schwartzian (vs hash)
Re^5: Benchmark, -s versus schwartzian (vs hash)
by ambrus (Abbot) on Aug 23, 2004 at 11:56 UTC

    The node you've mentioned actually uses an even faster form of the Schwartzian transform I've completely forgot about.

    Thus, I've added it to my benchmark too:

    sub sort_arr { my @h = map -s, @all; @results = @all[sort {$h[$a]<=>$h[$b]} 0..@h-1]; }

    The results are amazing: this form is about 1.5 times as efficent than any of the other ones.

      Yes, because it uses an array, and only one array.

      What's even more important to me is that it's also decidely easier on memory. Every single array in Perl has a minimum overhead of about 100 bytes without even counting the individual scalars inside it (and the one holding the reference to it..). When you're trying to sort a couple dozen million elements with a Schwartzian transform, as I've had to, that adds up alarmingly. In comparison, this method is basically free in terms of memory cost.

      Nitpick: you should really say 0 .. $#h when that's what you mean, as is the case here.

      Makeshifts last the longest.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://385050]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (11)
As of 2014-09-02 10:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (21 votes), past polls