PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: preg_match vs. strpos (simple)

No Description

Run this test again Return to test menu

Historical Results

Based on (3) saved test runs, The test labeled "preg_match()" was (on average) the faster by 0.0246 seconds, (2.875% faster)

preg_match() 100%
strpos() 97.125%

The preg_match() test took 0.8296 seconds.
The strpos() test took 0.8542 seconds.

Nitty-Gritty

Each test case ran 20 random code order iterations consisting of 202,513 loops for a total of 4,050,260 runs.

  • Line execution difference (0.000006) milliseconds.
  • Avg difference (0.000) milliseconds per 202,513 loops.
  • Total difference 24.56 milliseconds for 4,050,260 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, "preg_match()", was:

if (preg_match('~http://www\.google\.com/~', $GLOBALS['dummy']) != 0)
	$GLOBALS['dummy2'] = 42;

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

if (strpos($GLOBALS['dummy'], 'http://wwww.google.com/') !== false)
	$GLOBALS['dummy2'] = 42;

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