Warning: Division by zero in /var/customers/webs/stc/benchmark/index.php on line 256 Test: recurison vs. not (trivial)

PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: recurison vs. not (trivial)

What is the cost of a recursive algorithm vs. a non-recursive one?

Run Again Test Menu

Result

Unfortunately, no history for this test is available.

Code

The first test, "non-recursive", was:

/*
function recurse_not($i)
{
	$result = 0;

	while ($i > 0)
	{
		$result += $i;
		$i -= 5;
	}

	return $result;
}
*/

$result = recurse_not(5000);

The second test, "recursive", was:

/*
function recurse_normal($i)
{
	if ($i > 0)
		return $i + recurse_normal($i - 5);
	else
		return 0;
}
*/

$result = recurse_normal(5000);

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