Last active
December 11, 2017 12:17
-
-
Save kn007/0669836613cbde029257e2b7c3101b55 to your computer and use it in GitHub Desktop.
get EXTENSION performance: preg_match vs pathinfo
This file contains 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 | |
function microtime_float() | |
{ | |
list($usec, $sec) = explode(" ", microtime()); | |
return ((float)$usec + (float)$sec); | |
} | |
$url = 'https://files.kn007.net/aw-lol-concert.flv?v=1'; | |
$start=microtime_float(); | |
for ($i = 3000000; $i > 0; $i--) { | |
preg_match("/\.(\w+)($|\?|\#)/",$url,$str); | |
} | |
$end = microtime_float(); | |
echo("<br/> t i m e :" . round( $end - $start ,2) ."<br/>"); | |
$start=microtime_float(); | |
for ($i = 3000000; $i > 0; $i--) { | |
pathinfo( parse_url( $url, PHP_URL_PATH ), PATHINFO_EXTENSION ); | |
} | |
$end = microtime_float(); | |
echo("<br/> t i m e :" . round( $end - $start ,2) ."<br/>"); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment