PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: chr v. pack

Note that this test uses concatenation for many chr()'s vs. one pack(). In a case with many calls to pack(), the result might be different (but this is a less common use.)

Run this test again Return to test menu

Historical Results

Based on (6) saved test runs, The test labeled "chr()" was (on average) the faster by 0.0201 seconds, (2.717% faster)

chr() 100%
pack() 97.283%

The chr() test took 0.7207 seconds.
The pack() test took 0.7408 seconds.

Nitty-Gritty

Each test case ran 20 random code order iterations consisting of 183,563 loops for a total of 3,671,250 runs.

  • Line execution difference (0.000005) milliseconds.
  • Avg difference (0.000) milliseconds per 183,563 loops.
  • Total difference 20.13 milliseconds for 3,671,250 loops

The iteration variablity for Code 1 was (0.0000) milliseconds and Code 2 was (0.0000) 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) . chr(65) . chr(65) . chr(65);

The second test, "pack()", was:

$GLOBALS['dummy'] = pack('C4', 65, 65, 65, 65);

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