PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: Exceptions vs. return code (pass)

No Description

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

Result: Discarded

The test labeled "Exceptions" was the faster by 0.0138 seconds, (1.168% faster)

Exceptions 100%
return code 98.832%

The Exceptions test took 1.1635 seconds.
The return code test took 1.1772 seconds.

Nitty-Gritty

Each test case ran 20 random code order iterations consisting of 222,627 loops for a total of 4,452,540 runs.

  • Line execution difference (0.000003) milliseconds.
  • Avg difference (0.688) milliseconds per 222,627 loops.
  • Total difference 13.75 milliseconds for 4,452,540 loops

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