PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: Exceptions vs. return code (fail)

No Description

Run this test again Return to test menu

Result: Discarded

The test labeled "return code" was the faster by 0.1569 seconds, (9.060% faster)

return code 100%
Exceptions 90.94%

The return code test took 1.5753 seconds.
The Exceptions test took 1.7322 seconds.

Nitty-Gritty

Each test case ran 20 random code order iterations consisting of 286,349 loops for a total of 5,726,980 runs.

  • Line execution difference (0.000027) milliseconds.
  • Avg difference (7.847) milliseconds per 286,349 loops.
  • Total difference 156.94 milliseconds for 5,726,980 loops

The iteration variablity for Code 1 was (19.5188) milliseconds and Code 2 was (25.7577) 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 (return_false() === false)
		$GLOBALS['dummy']++;
}

The second test, "Exceptions", was:

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

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