Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

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

by Anonymous Monk
on Aug 23, 2004 at 09:19 UTC ( #385030=note: print w/ replies, xml ) Need Help??


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

I'm curious which comparison routines get optimized.
No block, $a <=> $b, $b <=> $a, $a cmp $b and $b cmp $a.
I don't see why you'd be surprised that creating a single hash would be faster than creating a ton of tiny anonymous arrays.
No lookup would even be faster. With a GRT you don't use block with sort, and hence, no array or hash lookup.
use Benchmark "cmpthese"; our @files = glob "/bin/*"; our (@o, @s, @g); cmpthese -1 => { ordinary => '@o = sort {-s $a <=> -s $b} @files', st => '@s = map $_ -> [0], sort {$a -> [1] <=> $b -> [1]} map [$_ => -s], @files', grt => '@g = map substr ($_, 8), sort map sprintf ("%08d%s", -s, $_), @files', }; die unless "@o" eq "@s" && "@o" eq "@g"; __END__ Rate ordinary st grt ordinary 684/s -- -54% -63% st 1492/s 118% -- -20% grt 1864/s 172% 25% --


Comment on Re^3: Benchmark, -s versus schwartzian (vs hash)
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (11)
As of 2014-07-23 11:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (140 votes), past polls