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.)

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

Result: Discarded

The test labeled "chr()" was the faster by 0.0928 seconds, (13.489% faster)

chr() 100%
pack() 86.511%

The chr() test took 0.5954 seconds.
The pack() test took 0.6882 seconds.


Each test case ran 20 random code order iterations consisting of 134,422 loops for a total of 2,688,440 runs.

  • Line execution difference (0.000035) milliseconds.
  • Avg difference (4.642) milliseconds per 134,422 loops.
  • Total difference 92.83 milliseconds for 2,688,440 loops

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


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 (