Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $str = "abcdefg";
- $length = strlen($str);
- $start = microtime(true);
- for ($m = 1000000; $m > 0; $m--) {
- for ($i = 0; $i < $length; $i++)
- {
- $a = 2*$i;
- }
- }
- echo "with strlen precalculated: " . (microtime(true) - $start) . "\n";
- $start = microtime(true);
- for ($m = 1000000; $m > 0; $m--) {
- for ($i = 0; $i < strlen($str); $i++)
- {
- $a = 2*$i;
- }
- }
- echo "with strlen in the loop: " . (microtime(true) - $start) . "\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement