Test: create_function vs. func callback
Using a pre-created function, is there any penalty in calling it versus a regular free function using a callback?
Run this test again Return to test menuResult: Discarded
The test labeled "create_function()" was the faster by 0.0615 seconds, (4.556% faster)
The create_function() test took 1.2879 seconds.
The regular callback test took 1.3494 seconds.
Nitty-Gritty
Each test case ran 20 random code order iterations consisting of 284,118 loops for a total of 5,682,360 runs.
- Line execution difference (0.000011) milliseconds.
- Avg difference (3.074) milliseconds per 284,118 loops.
- Total difference 61.48 milliseconds for 5,682,360 loops
The iteration variablity for Code 1 was (11.6434) milliseconds and Code 2 was (11.4300) milliseconds. The lower and the closer together there values are the more accurate the results are.
Code
The first test, "create_function()", was:
/* $GLOBALS['dummy'] = create_function('', ' $x = 0; $x += 5; if ($x >= 5) $x = 0; $x; $x;'); */ $GLOBALS['dummy']();
The second test, "regular callback", was:
/* function dummy() { $x = 0; $x += 5; if ($x >= 5) $x = 0; $x; $x; } $GLOBALS['dummy_cb'] = 'dummy'; */ $GLOBALS['dummy_cb']();