PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: preg_split vs. explode/str_replace

No Description

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

Result: Discarded

The test labeled "explode()" was the faster by 0.0527 seconds, (4.219% faster)

explode() 100%
preg_split() 95.781%

The explode() test took 1.1963 seconds.
The preg_split() test took 1.249 seconds.

Nitty-Gritty

Each test case ran 20 random code order iterations consisting of 286,251 loops for a total of 5,725,020 runs.

  • Line execution difference (0.000009) milliseconds.
  • Avg difference (2.635) milliseconds per 286,251 loops.
  • Total difference 52.69 milliseconds for 5,725,020 loops

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

Code

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

$GLOBALS['dummy2'] = preg_split('~\r\n|\r|\n~', $GLOBALS['dummy']);

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

$GLOBALS['dummy2'] = explode("\n", str_replace(array("\r\n", "\r"), "\n", $GLOBALS['dummy']));

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