Created
November 2, 2015 09:28
-
-
Save tarzak/4cf5a49de4ce2692cd27 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 arr = [1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10] | |
, i | |
, sum | |
; | |
console.time("while"); | |
i = arr.length; | |
sum = 0; | |
while (i--) | |
sum+=arr[i] | |
console.timeEnd("while"); | |
console.time("for"); | |
length = arr.length; | |
i = 0; | |
sum = 0; | |
for (; i < length; i += 1) | |
sum += arr[i]; | |
console.timeEnd("for"); | |
console.time("reduce"); | |
arr.reduce(function(prev,cur) { | |
return prev += cur; | |
}, 0); | |
console.timeEnd("reduce"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment