Created
August 18, 2014 16:56
-
-
Save hopeseekr/ef0a389943c61e6c9b22 to your computer and use it in GitHub Desktop.
HackLang Benchmark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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