I read that turning off tainting when building Perl can give you a speedup. Tainting also appears to be on the way out: it’s not needed for Mojolicious, for example. I brew my Perls so wondered how to do it. Some digging in the Perl distribution’s INSTALL file led me to a section on tainting. This suggested a flag. The next rabbit hole was how to get perlbrew to pass flags. Doing that and verifying with –verbose led me to:
export PERLBREW_CONFIGURE_FLAGS=-DNO_TAINT_SUPPORT
perlbrew --verbose install perl-5.36.0
And now some totally unscientific benchmarking using different Perl versions:
A simple benchmark suggested by David Farrell: https://www.perl.com/article/40/2013/9/29/How-to-benchmark-Perl-code-for-speed/
Perl-5.38.0 taint enabled:
equalsAssign: 11 wallclock secs
(10.19 usr + 0.05 sys = 10.24 CPU) @ 200453.61/s (n=2052645)
shiftAssign: 10 wallclock secs
(10.12 usr + 0.03 sys = 10.15 CPU) @ 202096.55/s (n=2051280)
Perl-5.38.0 taint disabled:
equalsAssign: 11 wallclock secs
(10.52 usr + 0.02 sys = 10.54 CPU) @ 207983.40/s (n=2192145)
shiftAssign: 11 wallclock secs
(10.51 usr + 0.01 sys = 10.52 CPU) @ 206375.10/s (n=2171066)
The code:
#!env perl
use strict;
use warnings;
use Benchmark qw/cmpthese timethese/;
timethese(-10, {
shiftAssign => sub { my @alphabet = ('A'..'Z');
for (my $i = 0; $i < 26; $i++){
my $letter = shift @alphabet;
}
},
equalsAssign => sub { my @alphabet = ('A'..'Z');
for (my $i = 0; $i < 26; $i++){
my $letter = $alphabet[$i];
}
},
});
So all-in-all about 10% in a handwaving kind of way.