Created
May 5, 2012 09:47
-
-
Save pulzarraider/2601230 to your computer and use it in GitHub Desktop.
Test performance of parse_url with or without @ + version check
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| header('Content-Type: text/plain'); | |
| error_reporting(E_ALL); | |
| $url = 'http://username:password@hostname/path?arg=value#anchor'; | |
| $iterations = 100000; | |
| //initialization | |
| $x = parse_url($url); | |
| $i = 0; | |
| //------------------------------------------------- | |
| $start = microtime(true); | |
| for ($i = 0; $i < $iterations; $i++) { | |
| $x = parse_url($url); | |
| } | |
| $end = microtime(true); | |
| echo 'parse_url without @: '.($end - $start)."\n"; | |
| //------------------------------------------------- | |
| $start = microtime(true); | |
| for ($i = 0; $i < $iterations; $i++) { | |
| $x = @parse_url($url); | |
| } | |
| $end = microtime(true); | |
| echo 'parse_url with @: '.($end - $start)."\n"; | |
| //------------------------------------------------- | |
| $start = microtime(true); | |
| for ($i = 0; $i < $iterations; $i++) { | |
| $x = PHP_VERSION_ID <= 50302 ? @parse_url($url) : parse_url($url); | |
| } | |
| $end = microtime(true); | |
| echo 'parse_url version check(tern): '.($end - $start)."\n"; | |
| //------------------------------------------------- | |
| $start = microtime(true); | |
| for ($i = 0; $i < $iterations; $i++) { | |
| $x = PHP_VERSION_ID > 50302 ? parse_url($url) : @parse_url($url); | |
| } | |
| $end = microtime(true); | |
| echo 'parse_url version check(tern2): '.($end - $start)."\n"; | |
| //------------------------------------------------- | |
| $start = microtime(true); | |
| for ($i = 0; $i < $iterations; $i++) { | |
| if (PHP_VERSION_ID <= 50302) { | |
| $x = @parse_url($url); | |
| } else { | |
| $x = parse_url($url); | |
| } | |
| } | |
| $end = microtime(true); | |
| echo 'parse_url version check(if): '.($end - $start)."\n"; | |
| //------------------------------------------------- | |
| $start = microtime(true); | |
| for ($i = 0; $i < $iterations; $i++) { | |
| if (PHP_VERSION_ID < 50303) { | |
| $x = @parse_url($url); | |
| } else { | |
| $x = parse_url($url); | |
| } | |
| } | |
| $end = microtime(true); | |
| echo 'parse_url version check(if2): '.($end - $start)."\n"; | |
| //------------------------------------------------- | |
| $start = microtime(true); | |
| for ($i = 0; $i < $iterations; $i++) { | |
| if (PHP_VERSION_ID > 50302) { | |
| $x = parse_url($url); | |
| } else { | |
| $x = @parse_url($url); | |
| } | |
| } | |
| $end = microtime(true); | |
| echo 'parse_url version check(if3): '.($end - $start)."\n"; | |
| //------------------------------------------------- | |
| function parseUrl1($url) | |
| { | |
| if (PHP_VERSION_ID > 50302) { | |
| return parse_url($url); | |
| } | |
| return @parse_url($url); | |
| } | |
| $start = microtime(true); | |
| for ($i = 0; $i < $iterations; $i++) { | |
| $x = parseUrl1($url); | |
| } | |
| $end = microtime(true); | |
| echo 'parse_url version check(func call1): '.($end - $start)."\n"; | |
| //------------------------------------------------- | |
| function parseUrl2($url) | |
| { | |
| if (PHP_VERSION_ID <= 50302) { | |
| return @parse_url($url); | |
| } | |
| return parse_url($url); | |
| } | |
| $start = microtime(true); | |
| for ($i = 0; $i < $iterations; $i++) { | |
| $x = parseUrl2($url); | |
| } | |
| $end = microtime(true); | |
| echo 'parse_url version check(func call2): '.($end - $start)."\n"; | |
| //------------------------------------------------- | |
| function parseUrl3($url) | |
| { | |
| if (PHP_VERSION_ID <= 50302) { | |
| return @parse_url($url); | |
| } else { | |
| return parse_url($url); | |
| } | |
| } | |
| $start = microtime(true); | |
| for ($i = 0; $i < $iterations; $i++) { | |
| $x = parseUrl3($url); | |
| } | |
| $end = microtime(true); | |
| echo 'parse_url version check(func call3): '.($end - $start)."\n"; | |
| //------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment