Thank you for looking into this, dave_the_m. But there's still performance issue if integer, or float that appears to be integer, is not the first, but last element of array. Then there's just one expensive-to-free element in derived array?
use strict;
use warnings;
use Devel::Peek;
use Benchmark qw/ cmpthese timeit /;
our @a = map log, 2..1e6;
push @a, 0/1;
print "************ a ************\n";
Dump $a[-2];
Dump $a[-1];
my @b = map $_ * 4, @a;
print "************ b ************\n";
Dump $b[-2];
Dump $b[-1];
cmpthese( -2, {
1 => 'my @c = map $_ * 4, @a',
2 => 'my @c = map $_ / (1/4), @a',
});
__END__
************ a ************
SV = NV(0x55f0580) at 0x55f0598
REFCNT = 1
FLAGS = (NOK,pNOK)
NV = 13.8155105579643
SV = NV(0x102a388) at 0x102a3a0
REFCNT = 1
FLAGS = (NOK,pNOK)
NV = 0
************ b ************
SV = NV(0xae879c8) at 0xae879e0
REFCNT = 1
FLAGS = (NOK,pNOK)
NV = 55.2620422318571
SV = PVNV(0x714ec8) at 0xae879f8
REFCNT = 1
FLAGS = (IOK,pIOK)
IV = 0
NV = 0
PV = 0
Rate 1 2
1 10.3/s -- -20%
2 12.8/s 25% --