Perl is not the fastest language

Back in December 2015, I noted that perl was getting faster. At the time, Isaac Gouy asked me to give him a heads up when 5.24 was released.

Perl 5.24 was released a few days ago. After confirming that the speed improvement was still there, I pinged Isaac. He has since updated Perl’s performance figures. Here is the improvement on the nbody benchmark on the machine Isaac uses for this the benchmarks game:

[ Perl 5.20.2 ranking on nbody benchmark ]
Perl 5.20.2 on nbody benchmark
[ Perl 5.24.0 ranking on nbody benchmark ]
Perl 5.24.0 on nbody benchmark

perl 5.20.2 used to take 17% more time than the Python 3 entry.

Now, perl 5.24.0 takes 18% less time than the Python 3 entry. Sure, it still takes 8100% more than the leading C++ entry, but that still represents a 30% improvement from the 11,600% more time it used to take.

On my laptop with the ancient Core 2 Duo T7600 CPU running Linux kernel 4.5.3 and perl compiled using gcc 6.1.1, the nbody benchmark ran in 12 minutes and 48 seconds. This compares nicely to a little over 20 minutes or so with 5.20.2.

On the same laptop, the stock perl 5.22.2 and python 3.5.1 that come with ArchLinux took 19m 47s and 20m 8s, respectively, to run the nbody benchmark. So, the improvement is real. The median improvement in Perl’s performance in the benchmarks game suite is around 10%. There were some benchmarks that ran slightly slower, but most had substantial improvements when run with perl 5.24.0.

On Windows 10 with a 2.1 Ghz Broadwell i3 CPU and perl compiled with Visual Studio 2013, I get 9m 17s with -march:AVX2, 9m 30s without. Again, these figures compare very favorably to the 16m 16s time I recorded on the same system back in December ’15.

I know a lot of people stick with perl 5.8 or even 5.6 in production systems for a variety of reasons, and I understand those reasons even if I do not agree with it all of them. However, if you are running any other version between 5.10 and 5.24, it means you have been enticed by at least one of the new features that have been added along the way. If you are in that camp, this may be the time to seriously consider whether you should switch to 5.24.

Building your own perl 5.24.0 is as easy as downloading the source, extracting it, and running ./Configure:

$ ./Configure -des -Dprefix=.../perl/5.24.0 -Duse64bitall
$ make test
$ make install

See if it makes a difference in your case.

In addition to the various performance improvements, it also offers the really nice language feature of postfix dereferencing. Along the way, you’ll also get the safer double diamond operator, introduced in 5.22, and hash randomization, introduced in 5.18.

PS: You can discuss this post on r/perl.

PPS: I know the person who optimized the Perl entry in the Benchmarks Game, Reini Urban, doesn’t really agree that the speed improvement is impressive, but, I still recommend you take a close look at whether it is worth it for your specific circumstance.