PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: using constants vs. variables

No Description

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

Result: Discarded

The test labeled "constants" was the faster by 0.009 seconds, (0.760% faster)

constants 100%
variables 99.24%

The constants test took 1.1809 seconds.
The variables test took 1.1899 seconds.

Nitty-Gritty

Each test case ran 20 random code order iterations consisting of 279,993 loops for a total of 5,599,860 runs.

  • Line execution difference (0.000002) milliseconds.
  • Avg difference (0.452) milliseconds per 279,993 loops.
  • Total difference 9.04 milliseconds for 5,599,860 loops

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

Code

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 (7.2.15-1+ubuntu16.04.1+deb.sury.org+1)