Warning: Division by zero in /var/customers/webs/stc/benchmark/index.php on line 256 Test: min/max vs. if

PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: min()/max() vs. if

Run Again Test Menu

Result

Unfortunately, no history for this test is available.

Code

The first test, "min()/max()", was:

$GLOBALS['dummy'] = 83;
for ($j = 0; $j < 100; $j++)
	$GLOBALS['dummy2'] = min(50, max(20, $GLOBALS['dummy']));

The second test, "ifs", was:

$GLOBALS['dummy'] = 83;
for ($j = 0; $j < 100; $j++)
{
	if ($GLOBALS['dummy'] < 20)
		$GLOBALS['dummy2'] = 20;
	elseif ($GLOBALS['dummy'] > 50)
		$GLOBALS['dummy2'] = 50;
	else
		$GLOBALS['dummy2'] = $GLOBALS['dummy'];
}

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