Next Making Programs Faster 116

Vanity, Vanity, all is Vanity

        use Benchmark;
        my $t = "some reasonably long string here";
        timethese(-5, { orig => 'orig_letter_histogram($t)' ,
                        mine => 'my_letter_histogram($t)' ,
                      });
        sub orig_letter_histogram {
          my $strdex = (length $_[0])-1;
          $letter_hist{substr($_[0],$_,1)}++     for (0..$strdex);
        }
        sub my_letter_histogram { 
          $letter_hist{$1}++ while $_[0] =~ m/(.)//gs;
        }
          orig histo 11.42  0.03  11.45
          while //gs 37.28  0.03  37.31
                NULL  0.04  0.00   0.04

Next Copyright © 2003 M. J. Dominus