Skip to content

Instantly share code, notes, and snippets.

@hopeseekr
Created August 18, 2014 16:56
Show Gist options
  • Save hopeseekr/ef0a389943c61e6c9b22 to your computer and use it in GitHub Desktop.
Save hopeseekr/ef0a389943c61e6c9b22 to your computer and use it in GitHub Desktop.
HackLang Benchmark
<?hh // partial
const int NUM_ELEMS = 10000000;
function main()
{
$rstart = microtime(true);
$randomNums = new Vector([]);
$randomNums->reserve(NUM_ELEMS);
for ($a = 0; $a < NUM_ELEMS; ++$a) {
$randomNums[] = rand(1, 1000);
//if ($a % 10000 == 0) { echo "Added " . $a . " rands\n"; }
}
$sum = 0;
for ($i = 0; $i < count($randomNums); ++$i) {
$sum += $randomNums[$i] * rand(1, 10) / 2;
//if ($i % 10000 == 0) { echo "Multiplied " . $i . " rands\n"; }
}
echo "\nRandom Sum: " . $sum . "\n";
$rend = microtime(true);
$execution_time = ($rend - $rstart);
echo '<div><b>Total Execution Time:</b> '.$execution_time.' secs</div>';
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment