PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: preg_match vs. strpos (simple)

No Description

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

Result: Discarded

The test labeled "strpos()" was the faster by 0.0231 seconds, (3.945% faster)

strpos() 100%
preg_match() 96.055%

The strpos() test took 0.5617 seconds.
The preg_match() test took 0.5848 seconds.

Nitty-Gritty

Each test case ran 20 random code order iterations consisting of 140,031 loops for a total of 2,800,620 runs.

  • Line execution difference (0.000008) milliseconds.
  • Avg difference (1.154) milliseconds per 140,031 loops.
  • Total difference 23.07 milliseconds for 2,800,620 loops

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