I got these results.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;} });
odd? Yeah.. However, when i tried this code: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)
i got these results:use Benchmark; my $sub=eval 'sub {('.join(',',map{'$s'.$_}1..1000).')=@base}'; @base=(1..1_000); timethese(1_000_000,{ '$'=>$sub, '@'=>sub{@s=@base;} });
Anyone have a brilliant explanation? (sorry for the pageful of $sXs, but i wanted to make the script just copy and paste).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)
In reply to list of scalars vs arrays, speed? by BUU
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |