in reply to Re^3: Whats quicker - passing along as variable to sub, or global var?
in thread Whats quicker - passing along as variable to sub, or global var?

Aaaah ok - missed that reply =) That would explain why testing1() is considerably quicker than testing2() in the below:

sub testing1 { print "At testing1 \n"; $_[0] =~ s/foo/test/g; } sub testing2 { print "At testing2 \n"; my $string = $_[0]; $string =~ s/foo/test/g; return $string; }
Thanks!

Andy
  • Comment on Re^4: Whats quicker - passing along as variable to sub, or global var?
  • Download Code

Replies are listed 'Best First'.
Re^5: Whats quicker - passing along as variable to sub, or global var?
by bart (Canon) on Apr 08, 2011 at 21:33 UTC
    Notice that in testing1() you're modifying the original string, so it's very likely the substitution does just plain nothing in all except the very first run.

    In testing2(), you're starting with a new string every time.

    So, that's probably skewing the benchmark.