[Chicago-talk] Removing "." from a string?

Andy_Bach at wiwb.uscourts.gov Andy_Bach at wiwb.uscourts.gov
Thu Jan 31 12:24:59 PST 2008


Did somebody *not* say "benchmark" ;->

# perl /tmp/dot.pl 10000000
Benchmark: timing 10000000 iterations of joinmatch, splitjoin, subst, 
whileindex...
 joinmatch:  4 wallclock secs ( 3.09 usr +  0.00 sys =  3.09 CPU) @ 
3236245.95/s (n=10000000)
 splitjoin:  3 wallclock secs ( 3.23 usr +  0.00 sys =  3.23 CPU) @ 
3095975.23/s (n=10000000)
     subst:  0 wallclock secs ( 0.91 usr +  0.00 sys =  0.91 CPU) @ 
10989010.99/s (n=10000000)
whileindex:  3 wallclock secs ( 2.73 usr +  0.00 sys =  2.73 CPU) @ 
3663003.66/s (n=10000000)

 use Benchmark qw(:all) ;


           # Use Perl code in strings...
#           timethese($count, {
#               'Name1' => '...code1...',
my $dotted_quad = '146.126.45.123';
my $count = shift || 10000;

           timethese($count, {
    'subst' => "\$dotted_quad    =~ s/\D//g;",

    'splitjoin' => "my \$digits      = join '', split /\D+/, 
\$dotted_quad;",

    'joinmatch' => "my \$digits      = join '', \$dotted_quad =~ m{ (\d+) 
}gx;",

    'whileindex' => "while( ( my \$i = index \$dotted_quad, '.' ) > 0 ) { 
substr \$dotted_quad, \$i, 1, ''; }; ",

           });

a

Andy Bach
Systems Mangler
Internet: andy_bach at wiwb.uscourts.gov
VOICE: (608) 261-5738  FAX 264-5932

"The Microsoft Exchange Information Store service depends on
the Microsoft Exchange Directory service which failed to
start because of the following error:
The operation completed successfully."
(actual MSE error msg)



More information about the Chicago-talk mailing list