Warning: Division by zero in /var/customers/webs/stc/benchmark/index.php on line 256 Test: tail recurison

PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: tail recurison

Is using tail-end recursion (where the recursion happens at the end of the function) any better?

Run Again Test Menu

Result

Unfortunately, no history for this test is available.

Code

The first test, "normal recursion", was:

/*
function recurse_tail($i, $inside)
{
	$data = '<div>' . $inside . '</div>';

	if ($i <= 0)
		return $data;
	else
		return recurse_tail($i - 1, $data);
}
*/

$result = recurse_tail(200, '');

The second test, "tail recursion", was:

/*
function recurse_normal($i, $inside)
{
	$data = '<div>';
	if ($i <= 0)
		$data .= $inside;
	else
		$data .= recurse_normal($i - 1, $data);
	$data .= '</div>';

	return $data;
}
*/

$result = recurse_normal(200, '');

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