Created
July 29, 2014 22:20
-
-
Save qiangxue/1a4a8befc968fa7399f8 to your computer and use it in GitHub Desktop.
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 | |
/** | |
strncmp : 0.099173069000244 | |
substr : 0.11933302879333 | |
substr_compare : 0.10576391220093 | |
*/ | |
$str = 'namespace yii\web'; | |
$str2 = 'namespace'; | |
$n = 100000; | |
$time = microtime(true); | |
for ($i=0; $i<$n; ++$i) { | |
strncmp($str, $str2, 9); | |
} | |
echo "Total : " . (microtime(true) - $time) . "\n"; | |
$time = microtime(true); | |
for ($i=0; $i<$n; ++$i) { | |
substr($str, 0, 9) === $str2; | |
} | |
echo "Total : " . (microtime(true) - $time) . "\n"; | |
$time = microtime(true); | |
for ($i=0; $i<$n; ++$i) { | |
substr_compare($str, $str2, 0, 9); | |
} | |
echo "Total : " . (microtime(true) - $time) . "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment