- microtime: documentation ( source)
- preg_match: documentation ( source)
- print_r: documentation ( source)
- parse_url: documentation ( source)
<?php
if (PHP_VERSION != '5.3.6') {
die("Incorrect version");
}
function a($url)
{
preg_match('!(?:(\w+)://)?(?:(\w+)\:(\w+)@)?([^/:]+)?(?:\:(\d*))?([^#?]+)?(?:\?([^#]+))?(?:#(.+$))?!i', $url, $out);
return $out;
}
function b($url)
{
$out = parse_url($url);
return $out;
}
$i = 100000;
$start = microtime(true);
while (--$i) {
$u[1] = a('example.com');
$u[2] = a('example.com/index.php');
$u[3] = a('example.com?foo=bar');
$u[4] = a('/index.php');
$u[5] = a('/index.php?foo=bar');
$u[6] = a('?foo=bar');
}
print_r($u);
echo microtime(true) - $start . "\n";
$i = 100000;
$start = microtime(true);
while (--$i) {
$u[1] = b('example.com');
$u[2] = b('example.com/index.php');
$u[3] = b('example.com?foo=bar');
$u[4] = b('/index.php');
$u[5] = b('/index.php?foo=bar');
$u[6] = b('?foo=bar');
}
print_r($u);
echo microtime(true) - $start . "\n";