I wish to comment more on my observations with nodejs
var sum = 0for (var i = 0; i < 100000000; i++) {
sum +=i //this is slower. Use sum = sum + 1//sum += 1 gave me 1.963235s on my machine whereas//sum = sum + 1 gave me 0.506995s
}
console.log(sum);
//I also rewrote it using while loop and the performance increasevar sum = 0;
limit = 100000000;
while(limit > 0)
{
sum = sum + limit--;
}
console.log(sum)
//I noticed the summation was completed in 0.214555s //The ram of my system is 6GB, core i3.