Warning: Division by zero in /var/customers/webs/stc/benchmark/index.php on line 256 Test: preg_match vs. strpos (complex)

PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: preg_match() vs. strpos() (complex)

Run Again Test Menu


Unfortunately, no history for this test is available.


The first test, "preg_match()", was:

if (preg_match('~http://([^\./]+\.[^/]+?)/~', $GLOBALS['dummy'], $match) != 0)
	$GLOBALS['dummy2'] = $match[1];

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

$pos_start = strpos($GLOBALS['dummy'], 'http://') + strlen('http://');
$pos_slash = strpos($GLOBALS['dummy'], '/', $pos_start + 2);

$pos_dot = strpos($GLOBALS['dummy'], '.', $pos_start + 1);
if ($pos_dot !== null && $pos_dot < $pos_slash)
	$GLOBALS['dummy2'] = substr($GLOBALS['dummy'], $pos_start, $pos_slash - $pos_start);

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