PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: (array) vs. array

Does the (array) cast work better than the array() construct?

Run this test again Return to test menu

Result: Discarded

The test labeled "(array)" was the faster by 0.0326 seconds, (5.783% faster)

(array) 100%
array() 94.217%

The (array) test took 0.5309 seconds.
The array() test took 0.5635 seconds.

Nitty-Gritty

Each test case ran 20 random code order iterations consisting of 125,446 loops for a total of 2,508,920 runs.

  • Line execution difference (0.000013) milliseconds.
  • Avg difference (1.629) milliseconds per 125,446 loops.
  • Total difference 32.59 milliseconds for 2,508,920 loops

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

Code

The first test, "(array)", was:

for ($j = 0; $j < 1000; $j++)
	$GLOBALS['dummy'] = (array) $j;

The second test, "array()", was:

for ($j = 0; $j < 1000; $j++)
	$GLOBALS['dummy'] = array($j);

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