Skip to content

Instantly share code, notes, and snippets.

@pborreli
Created May 5, 2013 12:59
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
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