PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: single class vs. associative arrays

This test creates objects or arrays, and fills them with equivalent data. The array is prefilled with nulls in attempt to be fair.

Run this test again Return to test menu

Historical Results

Based on (2) saved test runs, The test labeled "class" was (on average) the faster by 0.01 seconds, (1.206% faster)

class 100%
arrays 98.794%

The class test took 0.8229 seconds.
The arrays test took 0.8329 seconds.

Nitty-Gritty

Each test case ran 20 random code order iterations consisting of 213,391 loops for a total of 4,267,810 runs.

  • Line execution difference (0.000002) milliseconds.
  • Avg difference (0.000) milliseconds per 213,391 loops.
  • Total difference 10.05 milliseconds for 4,267,810 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.

Code

The first test, "class", was:

/*
class TestClass
{
	var $x, $y, $z;
}
*/

$data = new TestClass();

$data->x = 'test';
$data->y = 1;
$data->z = 5.5;

The second test, "arrays", was:

$data = array(
	'x' => null,
	'y' => null,
	'z' => null,
);

$data['x'] = 'test';
$data['y'] = 1;
$data['z'] = 5.5;

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