PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: Exceptions vs. return code (fail)

No Description

View test history (3) Run this test again Return to test menu

Result: Discarded

The test labeled "return code" was the faster by 0.0092 seconds, (1.902% faster)

return code 100%
Exceptions 98.098%

The return code test took 0.4738 seconds.
The Exceptions test took 0.483 seconds.

Nitty-Gritty

Each test case ran 20 random code order iterations consisting of 117,776 loops for a total of 2,355,520 runs.

  • Line execution difference (0.000004) milliseconds.
  • Avg difference (0.459) milliseconds per 117,776 loops.
  • Total difference 9.19 milliseconds for 2,355,520 loops

The iteration variablity for Code 1 was (1.4638) milliseconds and Code 2 was (1.0955) 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.15-1+ubuntu16.04.1+deb.sury.org+1)