Created
May 20, 2019 07:12
-
-
Save CezaryDanielNowak/bc305f2e8745e5038080cbcc38657c95 to your computer and use it in GitHub Desktop.
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
var values = [...new Array(32000000)].map((_, i) => i); | |
console.time('map + reduce'); | |
window.sum1 = values.map(x => x*x).reduce( (total,num,index,array) => total+num,0.0); | |
console.timeEnd('map + reduce'); | |
console.time('reduce'); | |
window.sum2 = values.reduce( (total,num,index,array) => total+num*num,0.0); | |
console.timeEnd('reduce'); | |
console.time('for loop'); | |
var sum = 0.0; | |
for (var i = 0; i < values.length;i++){ | |
var x = values[i]; | |
sum += x*x; | |
} | |
window.sum3 = sum | |
console.timeEnd('for loop'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment