| Next | Making Programs Faster | 110 |
Some months ago, I asked the Philadelphia Perl Mongers
Why do people bother to use the Schwartzian Transform?
# Schwartzian Transform
@sorted = map { $_->[0] }
sort { $b->[1] <=> $a->[1] }
map { [ $_, -M $_ ] } @files;
My idea was that this alternative is much easier to understand:
# Alternative
{ my %date;
$date{$_} = -M $_ for @files;
@sorted = sort { $date{$b} <=> $date{$a} } @files;
undef %date;
}
I did some benchmarks and found that it was only fractionally slower
NULL: 0.00u 0.00s 0.00total
ST: 8.73u 1.48s 10.21total
Hash: 9.59u 1.63s 11.22total
| Next | ![]() |
Copyright © 2003 M. J. Dominus |