Help for this page

Select Code to Download


  1. or download this
    use Benchmark;
     
    ...
                  "substr" => sub { ($char) = substr($string,4,1);},
                  "silly"  => sub { my $string2 = $string; $char = chop $s
    +tring2 while length $string2 >= 4;}, #note the local
                  });
    
  2. or download this
    Benchmark: running match, silly, substr, unpack, each for at least 1 C
    +PU seconds...
         match:  3 wallclock secs ( 1.00 usr +  0.02 sys =  1.02 CPU) @ 18
    +0382.35/s (n=183990)
         silly:  4 wallclock secs ( 1.15 usr +  0.09 sys =  1.24 CPU) @ 17
    +341.13/s (n=21503)
        substr:  2 wallclock secs ( 1.00 usr +  0.05 sys =  1.05 CPU) @ 94
    +4029.52/s (n=991231)
        unpack:  2 wallclock secs ( 1.02 usr +  0.06 sys =  1.08 CPU) @ 36
    +2192.59/s (n=391168)