r/perl•
mfontani

Benchmark for {threaded,nothreads} and {taint,notaint}

raptor

David Hodgkinson recently blogged at https://www.hodgkinson.org/2023/11/21/turn-of-tainting-in-brewed-perl/ about the impact of turning off taint, and I wanted to see more into it.

So I cribbed the simple tests from that blog post, and created a script to build docker images for multiple recent perl versions; install the required modules for the test suite (Benchmark, basically...) and then run these tests mentioned by David.

I got very surprising results: "nothreads-notaint" doesn't look at all better than "threads-taint". That is... odd.

I wanted to look more into it.

I ended looking at https://metacpan.org/pod/Benchmark::Perl::Formance, which unfortunately didn't fully build for me due to some prerequisites not building right.

But I could, and did, crib some tests from it - mostly about creating objects and using accessors/setters etc. on them, repeatedly.


See https://github.com/mfontani/perl-benchmark for the "code":

  1. bench.pl is the benchmarking program. It runs the tests it can, and spits out a TSV with (of note):
  • the @ARGV that the caller "passes in" to tell it what it's testing
  • the perl version from use Config, to verify it
  • the name of the test
  • the number of iterations done, divided by the cpu_p it took to execute them
  • other characteristics of the Benchmark object, for safekeeping
  1. dockerfiles.pl is what builds the dockerfiles for the wanted perl versions, as well as the runner script to run the tests
  2. report.pl -- assuming you've ran the benchmarks a few times and put them in report/ -- analyzes those and creates a index.html with the results, showing the average and the "error bars" for the deltas.

The (to me, VERY surprising) results are on https://mfontani.github.io/perl-benchmark/

To read it, remember that "higher is better": it's displaying number of iterations done per second, therefore if more iterations are done per second for the same task, the thing that does more of them is faster.

Oddly, it looks as if both "nothreads" and "notaint" don't offer any kind of speed-up at all. Worse, they're often worse than "threaded, and taint on". That's VERY surprising.

I've verified that indeed the "notaint" do have taint turned off, using something like:

$ docker run -it --entrypoint /usr/local/bin/perl perl-tests:5.38.1-nothreads-taint -wTE 'open my $fh, ">", "/$ARGV[0]"' asdf
Insecure dependency in open while running with -T switch at -e line 1.

... and that indeed the "nothreads" ones don't have threads support in them:

$ docker run -it --entrypoint /usr/local/bin/perl perl-tests:5.38.1-nothreads-taint -wTE 'use threads'
This Perl not built to support threads
Compilation failed in require at -e line 1.
BEGIN failed--compilation aborted at -e line 1.

What am I doing wrong? I'd expect the versions with no threads support and no taint support to be recognizably faster than the ones with threads and with taint.

Is it how I'm compiling them? Is it the benchmarks?

Posted Nov 28, 2023, 7:41 AM UTC

24
Loading comments…