Next | Making Programs Faster | 21 |
In contrast, consider this program:
for my $i (1 .. 100000) { my $n = $i / 100; my $s = square_root($n); }
sub square_root { my $tolerance = 0.000001; my $g = my $n = shift; while (abs($g * $g - $n) >= $tolerance) { $g = ($n/$g + $g)/2; } $g; }
real 0m10.211s user 0m9.570s sys 0m0.010s
This program spent 94% of its life using the CPU
Reducing the amount of computation by even 10% is likely to have a significant effect on the wallclock time
We say such a program is CPU bound
Next | Copyright © 2003 M. J. Dominus |