PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: define constants vs. variables

No Description

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

Result: Discarded

The test labeled "variables" was the faster by 0.0156 seconds, (1.474% faster)

variables 100%
constants 98.526%

The variables test took 1.0414 seconds.
The constants test took 1.057 seconds.

Nitty-Gritty

Each test case ran 20 random code order iterations consisting of 283,255 loops for a total of 5,665,100 runs.

  • Line execution difference (0.000003) milliseconds.
  • Avg difference (0.779) milliseconds per 283,255 loops.
  • Total difference 15.59 milliseconds for 5,665,100 loops

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

Code

The first test, "constants", was:

define('CONSTANT' . $GLOBALS['i'], $GLOBALS['x'] . $GLOBALS['y'] . $GLOBALS['z']);
$GLOBALS['i']++;

The second test, "variables", was:

$GLOBALS['CONSTANT' . $GLOBALS['i']] = $GLOBALS['x'] . $GLOBALS['y'] . $GLOBALS['z'];
$GLOBALS['i']++;

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