James Edward Gray II wrote:
On Apr 28, 2004, at 1:36 AM, Sumanth Sharma wrote:
##> $word =~s/aeiou/-/; but ..... $word =~ s/[aeiou]/-/g; ## will achieve the same thing.
Using s/// for something like tr/a-z/n-za-m/ is a little trickier, though certainly not impossible.
Anyway, is it true that "tr/aeiou/-/" is faster than "s/[aeiou]/-/g" ?.
Find out. The standard Benchmark module will tell you, if you ask nicely. If you have trouble with the code, give us a shout...
I figured I'd just pipe in my part since I find this topic quite interesting :)
Benchmark: timing 10000000 iterations of s/[aeiou]/-/g, s/aeiou/-/, tr/aeiou/-/...
s/[aeiou]/-/g: 7.10409 wallclock secs ( 4.77 usr + -0.01 sys = 4.76 CPU) @ 2100840.34/s (n=10000000)
s/aeiou/-/: 6.39385 wallclock secs ( 4.99 usr + 0.01 sys = 5.00 CPU) @ 2000000.00/s (n=10000000)
tr/aeiou/-/: 6.29083 wallclock secs ( 5.11 usr + 0.01 sys = 5.12 CPU) @ 1953125.00/s (n=10000000)
Rate tr/aeiou/-/ s/aeiou/-/ s/[aeiou]/-/g
tr/aeiou/-/ 1953125/s -- -2% -7%
s/aeiou/-/ 2000000/s 2% -- -5%
s/[aeiou]/-/g 2100840/s 8% 5% --
HTH :)
Lee.M - JupiterHost.Net
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>