PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: define constants vs. variables

No Description

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

Result: Discarded

The test labeled "constants" was the faster by 0.0286 seconds, (2.379% faster)

constants 100%
variables 97.621%

The constants test took 1.1724 seconds.
The variables test took 1.2009 seconds.


Each test case ran 20 random code order iterations consisting of 278,506 loops for a total of 5,570,120 runs.

  • Line execution difference (0.000005) milliseconds.
  • Avg difference (1.428) milliseconds per 278,506 loops.
  • Total difference 28.57 milliseconds for 5,570,120 loops

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


The first test, "constants", was:

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

The second test, "variables", was:


Running: Linux (x86_64:1 GB) PHP (