PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: preg_match vs. strpos (simple)

No Description

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

Result: Discarded

The test labeled "preg_match()" was the faster by 0.0516 seconds, (4.595% faster)

preg_match() 100%
strpos() 95.405%

The preg_match() test took 1.0722 seconds.
The strpos() test took 1.1239 seconds.


Each test case ran 20 random code order iterations consisting of 290,917 loops for a total of 5,818,340 runs.

  • Line execution difference (0.000009) milliseconds.
  • Avg difference (2.582) milliseconds per 290,917 loops.
  • Total difference 51.64 milliseconds for 5,818,340 loops

The iteration variablity for Code 1 was (3.8934) milliseconds and Code 2 was (4.7812) 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 (