in reply to Re: Using variables with tr///
in thread Using variables with tr///
with:Benchmark: timing 1000000 iterations of Eval, S_op... Eval: 140 wallclock secs (133.80 usr + 0.03 sys = 133.83 CPU) @ + 7472.17/s (n=1000000) S_op: 1 wallclock secs ( 0.81 usr + 0.00 sys = 0.81 CPU) @ 12 +34567.90/s (n=1000000)
Man, that's ugly.#!/usr/bin/perl -w use strict; $|++; use Benchmark; my $string = 'cat'; my $search = 'c'; my $replace = 'b'; timethese( 1000000, { Eval => sub { eval "$string =~ tr/$search/$replace/" + }, S_op => sub { $string =~ s/$search/$replace/g }, } );
-- Casey
|
|---|