in reply to Add a list of numbers together
This is fixed by adding explicit parenthesis after every shift().Warning: Use of "shift" without parens is ambiguous at benchadd.pl line 3. Type of arg 1 to shift must be array (not shift) at benchadd.pl line 3, near "shift,"
So my comments are:Benchmark: timing 100000 iterations of davorg, i43s, mdillon... davorg: 70 wallclock secs (55.52 usr + 0.06 sys = 55.58 CPU) @ 1799.21/s (n=100000) i43s: 20 wallclock secs (15.47 usr + 0.00 sys = 15.47 CPU) @ 6464.12/s (n=100000) mdillon: 8 wallclock secs ( 6.77 usr + 0.00 sys = 6.77 CPU) @ 14771.05/s (n=100000)
--ZZamboni
The benchmarking code:
use Benchmark; sub add_i43s { @_ > 1 ? add_i43s( shift() + shift(), @_ ) : shift() } sub add_davorg { eval join '+', @_ }; sub add_mdillon { my $sum; $sum += $_ for @_; $sum } timethese(100000, { 'i43s' => sub { add_i43s(1,2,3,4,5,6,7,8,9,10); }, 'davorg' => sub { add_davorg(1,2,3,4,5,6,7,8,9,10); }, 'mdillon' => sub { add_mdillon(1,2,3,4,5,6,7,8,9,10); } });
|
|---|