Skip to content

Instantly share code, notes, and snippets.

@kn007
Last active December 11, 2017 12:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kn007/0669836613cbde029257e2b7c3101b55 to your computer and use it in GitHub Desktop.
Save kn007/0669836613cbde029257e2b7c3101b55 to your computer and use it in GitHub Desktop.
get EXTENSION performance: preg_match vs pathinfo
<?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