Next Making Programs Faster 111

Vanity, Vanity, all is Vanity

I decided to apply Benchmark to these various approaches. I first compiled a list of 9952 filenames, then sorted them 10**7 times ...

        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;',
                }
        );

Next Copyright © 2003 M. J. Dominus