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 (2) saved test runs, The test labeled "strpos()" was (on average) the faster by 0.0034 seconds, (0.345% faster)

strpos() 100%
preg_match() 99.655%

The strpos() test took 0.9752 seconds.
The preg_match() test took 0.9785 seconds.


Each test case ran 20 random code order iterations consisting of 205,596 loops for a total of 4,111,910 runs.

  • Line execution difference (0.000001) milliseconds.
  • Avg difference (0.000) milliseconds per 205,596 loops.
  • Total difference 3.38 milliseconds for 4,111,910 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_match()", was:

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

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

if (strpos($GLOBALS['dummy'], '') !== false)
	$GLOBALS['dummy2'] = 42;

Running: Linux (x86_64:1 GB) PHP (