Last active
December 15, 2015 12:59
-
-
Save iNem0o/5263718 to your computer and use it in GitHub Desktop.
Vérifier la longueur d'une chaine en PHP : strlen() vs isset()
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 | |
$string = "hello world"; | |
$taille = 5; | |
$t = microtime(true); | |
for($i = 0;$i<10000;$i++) { | |
if(strlen($string) >= $taille) { | |
} | |
} | |
echo '<br> strlen($string) > 5 : '.round((microtime(true)-$t)*1000,2)." ms"; | |
$t = microtime(true); | |
for($i = 0;$i<10000;$i++) { | |
if(isset($string[$taille])) { | |
} | |
} | |
echo '<br> isset($string[5]) : '.round((microtime(true)-$t)*1000,2)." ms"; | |
?> | |
Résultats : | |
strlen($string) > 5 : 25.85 ms | |
isset($string[5]) : 4.02 ms |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment