PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: chr v. literal

How much worse is chr() than just a literal (if it's cleanly representable.)

Run this test again Return to test menu

Result: Discarded

The test labeled "literal" was the faster by 0.031 seconds, (2.951% faster)

literal 100%
chr() 97.049%

The literal test took 1.0205 seconds.
The chr() test took 1.0515 seconds.

Nitty-Gritty

Each test case ran 20 random code order iterations consisting of 290,062 loops for a total of 5,801,240 runs.

  • Line execution difference (0.000005) milliseconds.
  • Avg difference (1.552) milliseconds per 290,062 loops.
  • Total difference 31.03 milliseconds for 5,801,240 loops

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

Code

The first test, "chr()", was:

$GLOBALS['dummy'] = chr(65);

The second test, "literal", was:

$GLOBALS['dummy'] = 'A';

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