Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
$ gtime php substrstrlen.php
0.43 user
0.01 system
0:00.56 elapsed
0.43 user
0.01 system
0:00.50 elapsed
0.42 user
0.01 system
0:00.47 elapsed
$ gtime php strpos.php
0.27 user
0.01 system
0:00.30 elapsed
0.27 user
0.00 system
0:00.29 elapsed
0.28 user
0.01 system
0:00.30 elapsed
<?php
$class = 'Symfony\Bundle\FrameworkBundle\DependencyInjection\Configuration';
$prefix = 'Twig_';
for ($i = 0; $i < 1000000; ++$i) {
if (0 === strpos($class, $prefix)) {}
}
<?php
$class = 'Symfony\Bundle\FrameworkBundle\DependencyInjection\Configuration';
$prefix = 'Twig_';
for ($i = 0; $i < 1000000; ++$i) {
if (substr($class, 0, strlen($prefix)) === $prefix) {}
}
@staabm
Copy link

staabm commented May 5, 2013

you should move the strlen() out of the loop...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment