PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: Exceptions vs. return code (fail)

No Description

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

Result: Discarded

The test labeled "Exceptions" was the faster by 0.0477 seconds, (4.205% faster)

Exceptions 100%
return code 95.795%

The Exceptions test took 1.0864 seconds.
The return code test took 1.1341 seconds.

Nitty-Gritty

Each test case ran 20 random code order iterations consisting of 282,730 loops for a total of 5,654,600 runs.

  • Line execution difference (0.000008) milliseconds.
  • Avg difference (2.385) milliseconds per 282,730 loops.
  • Total difference 47.69 milliseconds for 5,654,600 loops

The iteration variablity for Code 1 was (5.0486) milliseconds and Code 2 was (3.1375) 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)