PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: preg_split vs. explode/str_replace

No Description

Run this test again Return to test menu

Historical Results

Based on (5) saved test runs, The test labeled "preg_split()" was (on average) the faster by 0.0075 seconds, (0.860% faster)

preg_split() 100%
explode() 99.14%

The preg_split() test took 0.8649 seconds.
The explode() test took 0.8724 seconds.


Each test case ran 20 random code order iterations consisting of 240,122 loops for a total of 4,802,444 runs.

  • Line execution difference (0.000002) milliseconds.
  • Avg difference (0.000) milliseconds per 240,122 loops.
  • Total difference 7.50 milliseconds for 4,802,444 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.


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 (