PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: array_walk vs. array_walk_recursive

Does the recursive variant have any benefit over rolling our own recursion?

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

Result: Discarded

The test labeled "array_walk()" was the faster by 0.0445 seconds, (4.101% faster)

array_walk() 100%
array_walk_recursive() 95.899%

The array_walk() test took 1.0402 seconds.
The array_walk_recursive() test took 1.0847 seconds.


Each test case ran 20 random code order iterations consisting of 276,441 loops for a total of 5,528,820 runs.

  • Line execution difference (0.000008) milliseconds.
  • Avg difference (2.224) milliseconds per 276,441 loops.
  • Total difference 44.48 milliseconds for 5,528,820 loops

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


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

function foo_manual(&$v)
	if (is_array($v))
		array_walk($v, 'foo_manual');

array_walk($GLOBALS['dummy'], 'foo_manual');

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

function foo_auto(&$v)

array_walk_recursive($GLOBALS['dummy'], 'foo_auto');

Running: Linux (x86_64:1 GB) PHP (