Created
December 2, 2011 14:47
-
-
Save piscisaureus/1423488 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var count = 3e6, | |
values = new Array(count), | |
repeats = 10; | |
console.log('generating numbers'); | |
for (var i = 0; i < count; i++) { | |
values[i] = ~~(Math.random() * 10); // <-- integers | |
//values[i] = Math.random() * 10 // <-- doubles | |
} | |
console.log('done generating numbers'); | |
for (;;) { | |
var start = (new Date()).getTime(); | |
for (var x = 0; x < repeats; x++) { | |
var sum = 0; | |
for (var i = 0; i < count; i++) { | |
sum = sum + values[i]; | |
} | |
} | |
var end = (new Date()).getTime(); | |
console.log("sum = " + sum); | |
console.log("spent " + (end - start) / repeats + " ms"); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment