Next | Making Programs Faster | 111 |
There was a followup:
I decided to apply Benchmark to these various approaches. I first compiled a list of 9952 filenames, then sorted them 10**7 times ...
Here's the code he showed:
timethese(10**7, { 'CODE A' => '@sorted = sort { -M $b <=> -M $a } @filenames;', 'CODE B' => '@sorted = map { $_->[0] } sort {$b->[1] <=> $a->[1]} map {[$_, -M $_]} @filenames;', 'CODE C' => '$date{$_} = -M $_ for @filenames; @sorted = sort {$date{$b} <=> $date{$a} } @filenames; undef %date;', 'CODE D' => '@sorted = map $_->[0], sort {$b->[1] <=> $a->[1]} map [$_, -M $_], @filenames;', } );
The warning sign is already visible, although I didn't pick up on it yet
Next | Copyright © 2003 M. J. Dominus |