Ok, well both of these have the same affect:
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";
However, if I change the $string and $string2 to:

my $string = "sf osfpsid hfosidhf soifh sofihs foishfosihf soifh soifhsofihsfoihs foishf sofhfo ihsf oishfsoifhsf \n" x 1000000;

...then there is quite a considerable difference. The code in Test.pm is as follows:
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;
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.

Cheers

Andy

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.