Next |
Making Programs Faster |
102 |
use Benchmark;
sub one_by_one {
my (@c);
for (my $i; $i < 100000; $i++) {
$c[$i] = rand;
}
}
sub preallocate {
my (@c);
$#c = 99999;
for (my $i; $i < 100000; $i++) {
$c[$i] = rand;
}
}
timethese (100, { 'preallocate' => 'preallocate()',
'one_by_one' => 'one_by_one()'
} );
Benchmark: timing 100 iterations of one_by_one, preallocate...
one_by_one: 111 secs (50.85 usr 0.52 sys = 51.37 cpu)
preallocate: 148 secs (67.13 usr 0.57 sys = 67.70 cpu)
Next |
|
Copyright © 2003 M. J. Dominus |