PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: using constants vs. variables

No Description

Run this test again Return to test menu

Result: Discarded

The test labeled "constants" was the faster by 0.0104 seconds, (0.742% faster)

constants 100%
variables 99.258%

The constants test took 1.3972 seconds.
The variables test took 1.4077 seconds.

Nitty-Gritty

Each test case ran 20 random code order iterations consisting of 278,923 loops for a total of 5,578,460 runs.

  • Line execution difference (0.000002) milliseconds.
  • Avg difference (0.522) milliseconds per 278,923 loops.
  • Total difference 10.45 milliseconds for 5,578,460 loops

The iteration variablity for Code 1 was (10.7256) milliseconds and Code 2 was (12.6529) 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.25-1+ubuntu16.04.1+deb.sury.org+1)