PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: global vs. $GLOBALS

No Description

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

Result: Discarded

The test labeled "global" was the faster by 0.0245 seconds, (3.262% faster)

global 100%
$GLOBALS 96.738%

The global test took 0.7275 seconds.
The $GLOBALS test took 0.7521 seconds.

Nitty-Gritty

Each test case ran 20 random code order iterations consisting of 194,360 loops for a total of 3,887,200 runs.

  • Line execution difference (0.000006) milliseconds.
  • Avg difference (1.227) milliseconds per 194,360 loops.
  • Total difference 24.54 milliseconds for 3,887,200 loops

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

Code

The first test, "global", was:

for ($i = 0; $i < 100; $i++)
{
	global $dummy, $dummy2;

	$dummy2 = $dummy;
}

The second test, "$GLOBALS", was:

for ($i = 0; $i < 100; $i++)
	$GLOBALS['dummy2'] = $GLOBALS['dummy'];

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