Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^8: Benchmark, -s versus schwartzian (smarter [sort])

by tye (Sage)
on Aug 25, 2004 at 20:32 UTC ( [id://385812]=note: print w/replies, xml ) Need Help??


in reply to Re^7: Benchmark, -s versus schwartzian
in thread Benchmark, -s versus schwartzian

s/2%/50%/ (roughly, depending). And it isn't just the comparison routine that is the problem. Constructing a huge number of tiny arrays takes some time (and memory).

I think fast, flexible, stable sort can be rolled into a module that makes the key construction easy and natural where the module overhead is low and outside of the sorting and so using the module would give performance (in speed and memory use) on par with a very efficient hand-rolled solution and much faster than any general-purpose Perl sorting modules I've looked at.

Having sort default to sorting array references as you've specified certainly makes sense. The boring answer is that backward compatibility prevents it from happening in Perl5. I won't pretend to remember how this type of operation is likely to behave in Perl6.

- tye        

Replies are listed 'Best First'.
Re^9: Benchmark, -s versus schwartzian (smarter [sort])
by fizbin (Chaplain) on Aug 25, 2004 at 21:04 UTC
    Okay, fair enough - the allocation of all those arrays would probably hurt severely. Much better to do the sort-the-indexes trick you mention elsewhere in this thread, or the GRT variant mentioned in fast, flexible, stable sort.

    But as for backwards compatibility - are you sure? Isn't the sorting of array references at this point essentially a random shuffle? (Meaning that it is unspecified, and could be different each time you run perl, not that it can be used in a situation where you actually need a random shuffle) Couldn't some order therefore be imposed upon it?

    -- @/=map{[/./g]}qw/.h_nJ Xapou cets krht ele_ r_ra/; map{y/X_/\n /;print}map{pop@$_}@/for@/

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-03-28 18:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found