Next | Making Programs Faster | 162 |
sub letter_histogram { my $strdex = (length $_[0])-1; $letter_hist{substr($_[0],$_,1)}++ for (0..$strdex); }
Perhaps we could get a speedup by avoiding the repeated array lookup on @_?
sub letter_histogram { my $msg = shift; my $strdex = (length $msg)-1; $letter_hist{substr($msg,$_,1)}++ for (0..$strdex); }
Cost: shift plus an extra copy of the data
Before After
real 0m1.277s real 0m1.236s user 0m1.250s user 0m1.220s sys 0m0.020s sys 0m0.010s
No significant difference
Perhaps it really is .04 ms faster
But who the heck cares?
Other things I tried:
Use @letter_hist instead of %letter_hist
Call letter_histogram once on entire mbox instead of on each message
Next | Copyright © 2003 M. J. Dominus |