PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: using constants vs. variables

No Description

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

Result: Discarded

The test labeled "variables" was the faster by 0.0317 seconds, (7.156% faster)

variables 100%
constants 92.844%

The variables test took 0.4109 seconds.
The constants test took 0.4426 seconds.


Each test case ran 20 random code order iterations consisting of 86,001 loops for a total of 1,720,020 runs.

  • Line execution difference (0.000018) milliseconds.
  • Avg difference (1.584) milliseconds per 86,001 loops.
  • Total difference 31.67 milliseconds for 1,720,020 loops

The iteration variablity for Code 1 was (4.4893) milliseconds and Code 2 was (2.6954) 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 (