PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: redefine constant

No Description

Run this test again Return to test menu

Result: Discarded

The test labeled "!defined()" was the faster by 0.0096 seconds, (0.885% faster)

!defined() 100%
@define() 99.115%

The !defined() test took 1.0751 seconds.
The @define() test took 1.0847 seconds.

Nitty-Gritty

Each test case ran 20 random code order iterations consisting of 284,022 loops for a total of 5,680,440 runs.

  • Line execution difference (0.000002) milliseconds.
  • Avg difference (0.480) milliseconds per 284,022 loops.
  • Total difference 9.59 milliseconds for 5,680,440 loops

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

Code

The first test, "@define()", was:

@define('CONSTANT', $GLOBALS['dummy']);

The second test, "!defined()", was:

if (!defined('CONSTANT'))
	define('CONSTANT', $GLOBALS['dummy']);

Running: Linux (x86_64:1 GB) PHP (7.2.22-1+ubuntu16.04.1+deb.sury.org+1)