Next Making Programs Faster 30

Benchmark.pm

     use Benchmark;
     my $N = shift || 1000000;
     my $s = shift || "The quick brown fox jumps over the lazy dog";
     timethese($N,
               { substr => sub { substr($s, 0, 3) = "abc" },
                 regex  => sub { $s =~ s/.../abc/s },
               });
        regex:  7 wallclock secs
           ( 7.85 usr +  0.00 sys =  7.85 CPU) 
           @ 127388.54/s (n=1000000)
        substr:  7 wallclock secs
           ( 8.24 usr +  0.00 sys =  8.24 CPU) 
           @ 121359.22/s (n=1000000)


Next Copyright © 2003 M. J. Dominus