Skip to content

Instantly share code, notes, and snippets.

@thbourlove
Created August 24, 2013 01:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thbourlove/6325403 to your computer and use it in GitHub Desktop.
Save thbourlove/6325403 to your computer and use it in GitHub Desktop.
<?php
$arr = [];
for ($i = 0; $i < 100000; $i++) {
$arr[] = rand();
}
$timeStart1 = microtime(true);
foreach ($arr as $value){
$tmp = $value > 1000000000 ? $value : $value - 1000000000;
}
$timeEnd1 = microtime(true);
var_export($timeEnd1 - $timeStart1);
print "\n";
$timeStart2 = microtime(true);
foreach ($arr as $value){
if ($value > 1000000000) {
$tmp = $value;
} else {
$tmp = $value - 1000000000;
}
}
$timeEnd2 = microtime(true);
var_export($timeEnd2 - $timeStart2);
/*
0.010640144348145
0.0077409744262695
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment