PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: preg_split vs. explode/str_replace

No Description

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

Result: Saved

The test labeled "preg_split()" was the faster by 0.0301 seconds, (2.917% faster)

preg_split() 100%
explode() 97.083%

The preg_split() test took 1.0028 seconds.
The explode() test took 1.033 seconds.

Nitty-Gritty

Each test case ran 20 random code order iterations consisting of 273,111 loops for a total of 5,462,220 runs.

  • Line execution difference (0.000006) milliseconds.
  • Avg difference (1.507) milliseconds per 273,111 loops.
  • Total difference 30.13 milliseconds for 5,462,220 loops

The iteration variablity for Code 1 was (1.3206) milliseconds and Code 2 was (1.1740) 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.19-1+ubuntu16.04.1+deb.sury.org+1)