<?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";
- Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.5, 5.3.7 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.10, 7.2.0
- Incorrect version
- Output for 5.3.6
- Array
(
[1] => Array
(
[0] => example.com
[1] =>
[2] =>
[3] =>
[4] => example.com
)
[2] => Array
(
[0] => example.com/index.php
[1] =>
[2] =>
[3] =>
[4] => example.com
[5] =>
[6] => /index.php
)
[3] => Array
(
[0] => example.com?foo=bar
[1] =>
[2] =>
[3] =>
[4] => example.com?foo=bar
)
[4] => Array
(
[0] => /index.php
[1] =>
[2] =>
[3] =>
[4] =>
[5] =>
[6] => /index.php
)
[5] => Array
(
[0] => /index.php/?foo=bar
[1] =>
[2] =>
[3] =>
[4] =>
[5] =>
[6] => /index.php/
[7] => foo=bar
)
[6] => Array
(
[0] => ?foo=bar
[1] =>
[2] =>
[3] =>
[4] => ?foo=bar
)
)
1.2550489902496
Array
(
[1] => Array
(
[path] => example.com
)
[2] => Array
(
[path] => example.com/index.php
)
[3] => Array
(
[path] => example.com
[query] => foo=bar
)
[4] => Array
(
[path] => /index.php
)
[5] => Array
(
[path] => /index.php/
[query] => foo=bar
)
[6] => Array
(
[query] => foo=bar
)
)
0.34682893753052
preferences:
152.73 ms | 405 KiB | 175 Q