Next Making Programs Faster 21

CPU Bound Programs

        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

Next Copyright © 2003 M. J. Dominus