PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: using constants vs. variables

No Description

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

Result: Discarded

The test labeled "variables" was the faster by 0.0107 seconds, (1.002% faster)

variables 100%
constants 98.998%

The variables test took 1.0572 seconds.
The constants test took 1.0679 seconds.


Each test case ran 20 random code order iterations consisting of 276,395 loops for a total of 5,527,900 runs.

  • Line execution difference (0.000002) milliseconds.
  • Avg difference (0.535) milliseconds per 276,395 loops.
  • Total difference 10.70 milliseconds for 5,527,900 loops

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


The first test, "constants", was:

$GLOBALS['test'] = CONSTANT + 1;

The second test, "variables", was:

$GLOBALS['test'] = $GLOBALS['CONSTANT'] + 1;

Running: Linux (x86_64:1 GB) PHP (