However, if I change the $string and $string2 to:my $string = "foo bar testing"; my $string2 = "foo bar testing"; use Benchmark; use Test; #################### # Test 1 #################### my $start = new Benchmark; Test::testing1($string); print qq|String is now: $string \n|; my $end = new Benchmark; my $diff = timediff($end, $start); print "Time taken was ", timestr($diff, 'all'), " seconds \n\n"; #################### # Test 2 #################### # start timer my $start = new Benchmark; $string2 = Test::testing2($string2); print qq|String2 is now: $string2 \n|; my $end = new Benchmark; my $diff = timediff($end, $start); print "Time taken was ", timestr($diff, 'all'), " seconds \n\n";
Judging from the above then - I'm guessing just editing $_[0] directly is gonna be the best option for us, as it seems to be a lot quicker.package Test; use strict; 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; } 1;
In reply to Re^2: Whats quicker - passing along as variable to sub, or global var?
by ultranerds
in thread Whats quicker - passing along as variable to sub, or global var?
by ultranerds
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |