Using the JIT compiler
Learn how to use the JIT compiler in PHP 8 applications to improve efficiency.
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 ...