I was bored and decided to benchmark ($s1,$s2 etc)=@ar vs @ar1=@ar2. should be roughly equal? Thats what you would think..
However, when i tried this code:
use Benchmark; @base=qw/one two three four five six seven/; timethese(1_000_000,{ '$'=>sub {($s1,$s2,$s3,$s4,$s5,$s6,$s7)=@base;}, '@'=>sub{@s=@base;} });
I got these results.
Benchmark: timing 1000000 iterations of $, @... $: 3 wallclock secs ( 2.86 usr + 0.00 sys = 2.86 CPU) @ 34 +9650.35/s (n=1000000) @: 11 wallclock secs (10.16 usr + 0.00 sys = 10.16 CPU) @ 98 +425.20/s (n=1000000)
odd? Yeah.. However, when i tried this code:
use Benchmark; my $sub=eval 'sub {('.join(',',map{'$s'.$_}1..1000).')=@base}'; @base=(1..1_000); timethese(1_000_000,{ '$'=>$sub, '@'=>sub{@s=@base;} });
i got these results:
Benchmark: timing 1000000 iterations of $, @... $: 131 wallclock secs (130.77 usr + 0.00 sys = 130.77 CPU) @ 7647.01/s (n=1000000) @: 149 wallclock secs (149.56 usr + 0.00 sys = 149.56 CPU) @ 6686.28/s (n=1000000)
Anyone have a brilliant explanation? (sorry for the pageful of $sXs, but i wanted to make the script just copy and paste).

Also note that i am running these test on this box: Win98se, amd1600mhz, 512ddr ram. So if anyone else wants to try the above code with different configs and see if its a win98 thing or something.

In reply to list of scalars vs arrays, speed? by BUU

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.