Result: Discarded
The test labeled "min()/max()" was the faster by 0.0287 seconds, (2.308% faster)
The min()/max() test took 1.2148 seconds.
The ifs test took 1.2435 seconds.
Nitty-Gritty
Each test case ran 20 random code order iterations consisting of 289,711 loops for a total of 5,794,220 runs.
- Line execution difference (0.000005) milliseconds.
- Avg difference (1.435) milliseconds per 289,711 loops.
- Total difference 28.70 milliseconds for 5,794,220 loops
The iteration variablity for Code 1 was (11.1743) milliseconds and Code 2 was (9.1989) milliseconds. The lower and the closer together there values are the more accurate the results are.
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']; }