PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: Exceptions vs. return code (pass)

No Description

Run this test again Return to test menu

Historical Results

Based on (5) saved test runs, The test labeled "return code" was (on average) the faster by 0.0078 seconds, (0.966% faster)

return code 100%
Exceptions 99.034%

The return code test took 0.8026 seconds.
The Exceptions test took 0.8104 seconds.

Nitty-Gritty

Each test case ran 20 random code order iterations consisting of 214,021 loops for a total of 4,280,428 runs.

  • Line execution difference (0.000002) milliseconds.
  • Avg difference (0.000) milliseconds per 214,021 loops.
  • Total difference 7.83 milliseconds for 4,280,428 loops

The iteration variablity for Code 1 was (0.0000) milliseconds and Code 2 was (0.0000) milliseconds. The lower and the closer together there values are the more accurate the results are.

Code

The first test, "return code", was:

for ($i = 0; $i < 100; $i++)
{
	if (no_return_false() === false)
		$GLOBALS['dummy']++;
}

The second test, "Exceptions", was:

for ($i = 0; $i < 100; $i++)
{
	try
	{
		no_throw_exception();
	}
	catch (Exception $e)
	{
		$GLOBALS['dummy']++;
	}
}

Running: Linux (x86_64:1 GB) PHP (7.2.15-1+ubuntu16.04.1+deb.sury.org+1)