in reply to Re: Re: Thousands separator - this is getting annoying
in thread Thousands separator - this is getting annoying

A very good point, particularly because I'd say the benefit is *much much* more than slight:
use Benchmark; my $foo = join ',', ('bar') x 100; timethese(-10, { 's' => sub { (my $bar = $foo) =~ s/,//g }, 'tr' => sub { (my $bar = $foo) =~ tr/,//d }, });
Results:
Benchmark: running s, tr, each for at least 10 CPU seconds... s: 10 wallclock secs (10.00 usr + 0.00 sys = 10.00 CPU) @ 10 +150.70/s (n=101507) tr: 10 wallclock secs (10.01 usr + 0.00 sys = 10.01 CPU) @ 10 +9117.38/s (n=1092265)
tr is 10 times faster here! A definite improvement.

Replies are listed 'Best First'.
(tye)Re: Thousands separator - this is getting annoying
by tye (Sage) on Jan 17, 2001 at 03:58 UTC

    I guess this is close to a pet peave of mine...

    So, if I'm fetching 10,000 numbers of 300 digits each from my database, then using tr will save me 0.9 seconds. Nope, that sounds slight to me. (:

    Yes, use tr in place of s when you can. Sometimes the performance difference will matter, but not this time. The tr solution has no drawbacks here so go for it. Just don't overstate the benefit.

            - tye (but my friends call me "Tye")
      D'oh! I guess I'll have to watch out for that in the future...

      Funny thing is I am aware of tr but I think I was suffering from a brain cramp trying to solve a problem at work...

      I'm feeling much better now

      Thanks for pointing it out, though.(++ for those who corrected me)

      cheers,

      Mick