Skip to content

Instantly share code, notes, and snippets.

@joerayme
Created November 4, 2011 16:40
Show Gist options
  • Save joerayme/1339795 to your computer and use it in GitHub Desktop.
Save joerayme/1339795 to your computer and use it in GitHub Desktop.
Loop test
<?php
$array = array_fill(0, 50000, 'a');
$start = microtime(true);
for ($i = 0; $i < sizeof($array); $i++);
$end = microtime(true);
echo "Completed with sizeof in the loop in " . ($end - $start) . "s\n";
$start = microtime(true);
for ($i = 0, $total = sizeof($array); $i < $total; $i++);
$end = microtime(true);
echo "Completed without sizeof in the loop in " . ($end - $start) . "s\n";
// Output for me:
// Completed with sizeof in the loop in 0.0959849357605s
// Completed without sizeof in the loop in 0.01615691185s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment