in reply to Re^2: Should multiplication by integer be avoided in favour of division for performance reasons? (benchmark pitfalls)
in thread Should multiplication by integer be avoided in favour of division for performance reasons?
There is no @main::a. You are benchmarking couple of no-ops.
use strict; use warnings; use Benchmark qw/ cmpthese timeit /; our @b = my @a = map log, 1..1e6; timeit( 1, 'print "\$#a = $#a\n";' ); timeit( 1, 'print "\$#b = $#b\n";' ); cmpthese( -2, { a => '[ map $_ * 4, @a ]', b => '[ map $_ * 4, @b ]', }); cmpthese( -2, { 1 => '[ map $_ * 4, @b ]', 2 => '[ map $_ / (1/4), @b ]', }); __END__ $#a = -1 $#b = 999999 Rate b a b 7.70/s -- -100% a 10680591/s 138780824% -- Rate 1 2 1 7.76/s -- -28% 2 10.7/s 39% --
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Should multiplication by integer be avoided in favour of division for performance reasons? (benchmark pitfalls)
by dave_the_m (Monsignor) on Nov 29, 2019 at 14:35 UTC | |
by vr (Curate) on Nov 29, 2019 at 16:24 UTC | |
by dave_the_m (Monsignor) on Nov 29, 2019 at 19:32 UTC |