PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: arrays vs. variables

Not that using variables like this is good style, and array1 already mostly answers this.

Run this test again Return to test menu

Historical Results

Based on (5) saved test runs, The test labeled "$array[$n]" was (on average) the faster by 0.0167 seconds, (2.093% faster)

$array[$n] 100%
${'array_' . $n} 97.907%

The $array[$n] test took 0.7836 seconds.
The ${'array_' . $n} test took 0.8003 seconds.


Each test case ran 20 random code order iterations consisting of 194,984 loops for a total of 3,899,688 runs.

  • Line execution difference (0.000004) milliseconds.
  • Avg difference (0.000) milliseconds per 194,984 loops.
  • Total difference 16.75 milliseconds for 3,899,688 loops

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


The first test, "$array[$n]", was:

$array = array();
for ($i = 0; $i < 100; $i++)
	$array[$i] = $i;

The second test, "${'array_' . $n}", was:

for ($i = 0; $i < 100; $i++)
	${'array_' . $i} = $i;

Running: Linux (x86_64:1 GB) PHP (