in reply to Re^5: 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?

Bear in mind that Benchmark.pm does something like the equivalent of
eval q[ for my $i (1..$n) { my @c = map $_ * 4, @a; } ]
Since the same multiply op is used for all iterations, once it gets "poisoned" by trying to return an IV value for the last element of the first iteration, further calls to that op will start returning PVNVs. So for iterations 2+, all elements of @c will be PVNVs and thus slower to free.

It's also the case that multiply is fractionally slower at returning a PVNV value rather than an NV value.

Dave.

  • Comment on Re^6: Should multiplication by integer be avoided in favour of division for performance reasons? (benchmark pitfalls)
  • Download Code