Test: many classes vs. associative arrays
Does it make any difference when you have multiple classes being instantiated vs. multiple arrays? Note that both are wrapped in an eval to make it fair (another option would be to pre-create all of the classes, but this is more illustrative.)
Run this test again Return to test menuResult: Discarded
The test labeled "classes" was the faster by 0.0029 seconds, (0.647% faster)
The classes test took 0.4481 seconds.
The arrays test took 0.451 seconds.
Nitty-Gritty
Each test case ran 20 random code order iterations consisting of 126,582 loops for a total of 2,531,640 runs.
- Line execution difference (0.000001) milliseconds.
- Avg difference (0.146) milliseconds per 126,582 loops.
- Total difference 2.92 milliseconds for 2,531,640 loops
The iteration variablity for Code 1 was (1.2708) milliseconds and Code 2 was (0.7734) milliseconds. The lower and the closer together there values are the more accurate the results are.
Code
The first test, "classes", was:
$name = 'TestClass' . $GLOBALS['i']++; eval(' class ' . $name . ' { var $x, $y, $z; } $data = new ' . $name . '(); $data->x = \'test\'; $data->y = 1; $data->z = 5.5;');
The second test, "arrays", was:
$name = 'TestArray' . $GLOBALS['i']++; eval(' $' . $name . ' = array( \'x\' => null, \'y\' => null, \'z\' => null, ); $' . $name . '[\'x\'] = \'test\'; $' . $name . '[\'y\'] = 1; $' . $name . '[\'z\'] = 5.5;');