PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: else if vs. elseif

No Description

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

Result: Discarded

The test labeled "else if" was the faster by 0.0511 seconds, (3.198% faster)

else if 100%
elseif 96.802%

The else if test took 1.5458 seconds.
The elseif test took 1.5969 seconds.

Nitty-Gritty

Each test case ran 20 random code order iterations consisting of 269,860 loops for a total of 5,397,200 runs.

  • Line execution difference (0.000009) milliseconds.
  • Avg difference (2.553) milliseconds per 269,860 loops.
  • Total difference 51.06 milliseconds for 5,397,200 loops

The iteration variablity for Code 1 was (11.7163) milliseconds and Code 2 was (7.8154) milliseconds. The lower and the closer together there values are the more accurate the results are.

Code

The first test, "else if", was:

if ($GLOBALS['dummy_false'])
	$GLOBALS['dummy_false'] = true;
else if ($GLOBALS['dummy_true'])
	$GLOBALS['dummy_true'] = true;

The second test, "elseif", was:

if ($GLOBALS['dummy_false'])
	$GLOBALS['dummy_false'] = true;
elseif ($GLOBALS['dummy_true'])
	$GLOBALS['dummy_true'] = true;

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