Using the JIT compiler
Explore how to utilize the PHP 8 JIT compiler for enhanced performance by running a computation-intensive Mandelbrot benchmark. Understand configuration settings, command-line options, and advanced debugging methods to optimize code execution in PHP 8.
We'll cover the following...
Let's now have a look at the JIT compiler in action.
Utilizing the JIT compiler
In this example, we use a classic benchmark program that produces a Mandelbrot. This is an excellent test because it’s extremely computation-intensive. The implementation we use here is drawn from the implementation code produced by Dmitry Stogov, one of the PHP core development team members. We first run the program in PHP 7 using the -n flag. Here is the result:
Let’s get into the code.
Lines 11–16: We first define the Mandelbrot parameters. Especially important is the number of iterations (
MAX_LOOPS). A large number spawns more calculations and slows down overall production. We also capture the start time.Line 20: In order to facilitate multiple program runs, we add an option to capture a command line param,
-n. If this parameter is present, the Mandelbrot output is suppressed.Line 24–44: We then define a function,
iterate(), drawn ...