PHP8 Benchmark the Brainfuck Way

The demo source for this article can be found on my Github: github.com/karminski/P…

PHP8 has been released with a new and exciting JIT compilation engine. According to the official documentation: “It improved performance by approximately 3 times in comprehensive benchmarks and 1.5 to 2 times in some specific long-running applications. Typical application performance is comparable to PHP 7.4.

The official performance test results are shown below:

So what is the reality?

So I wrote a simple running demo, a brainfuck interpreter ported from Go.

PHP. Also contains brainfuck implementation of the Mandelbrot set. The program uses brainfuck language interpreter written in PHP to run the program written by Brainfuck to generate Mandelbo set. Then time it and compare its performance.

The configuration of my machine is Intel(R) Xeon(TM) E5-2680V2@ 2.8GHz.

PHP 8.0.0 does not enable jit test results

PHP 8.0.0 enables JIT test results

conclusion

According to the test data, it takes 6m20.973s when JIT is not enabled, and 2m48.527s when JIT is enabled. The demo program spent most of its time doing foo++; \`\`\`, \`\`\`foo–; ` ` `, array find and assignment of such operation, one of the most ` ` ` op_inc_dp ` ` ` logic, namely ` ` ` $dataPtr++; Executed 4,453,036,023 times.

In this test, the performance improvement with THE introduction of JIT in PHP 8 is significant. This opens up new possibilities for PHP. However, we also saw weak improvements in official testing of some complex applications, such as WordPress. It is not known whether the performance gains are not significant because JIT is still in its infancy or because WordPress is an existing project and the code cannot be optimized specifically for JIT. This part also needs to be evaluated by a detailed benchmark, such as using a flame map.

As a veteran of PHP 4, I have mixed feelings about PHP, and PHP currently lacks a strong ecosystem to reawaken. And that requires the combined efforts of the PHPer community. Expect PHP to do better in the future.

Reference

  • The Original brainfuck interpreter source code
  • The mandelbrot set fractal viewer in brainfuck written by Erik Bosman

License

  • The MIT License (MIT)