in reply to Re: Re: problems with tr///;
in thread problems with tr///;
So I tried a couple of benchmarks. (I'm using 5.6.1, build 626 from ActiveState.) Here's the code:
and here's the resultsuse Benchmark; $var = '\a\\aa\\\aaa\\\\aaaa'x100; print "s: "; timethis(100000, '$var =~ s/\\\//g'); # 3 \ for benchmark print "tr: "; timethis(100000, '$var =~ tr/\\\//d');
You can play with $var and see the effect on the timings. Maybe tr used to be faster, but that's no longer the case.s: timethis 100000: 1 wallclock secs ( 0.51 usr + 0.00 sys = 0.51 +CPU) @ 195694.72/s (n=100000) tr: timethis 100000: 2 wallclock secs ( 1.68 usr + 0.00 sys = 1.68 +CPU) @ 59453.03/s (n=100000)
<soapbox>
It's really beside the point. The point is the right tool for the job. In this case the right tool is the substitution operator. If you wanted to make multiple single character changes in the string then tr is what you want. Note the difference between:
</soapbox>$var =~ tr /ab/cd/; # and $var =~ s /ab/cd/g;
Have fun,
Carl Forde
|
---|
Replies are listed 'Best First'. | |
---|---|
Re4: problems with tr///;
by blakem (Monsignor) on Sep 27, 2001 at 02:14 UTC | |
by cforde (Monk) on Sep 27, 2001 at 20:48 UTC |