3 ms·
Though trying to add the numbers for 1 to a million in a loop javascript was about 10 - 20 times faster when I tried it.
by tim333 8y ago
Though trying to add the numbers for 1 to a million in a loop javascript was about 10 - 20 times faster when I tried it.
- deleted 8y ago[deleted]
- sametmax 8y agoYou would use sum(range()) in a Python though. Remember that many things you do manually in JS have a better, automatic and faster way in the stlib. Besides, if calculations are important, you would use numpy.
- tim333 8y agoAh yes. sum(range()) in Python vs for(i=1...) in js was much closer, about 20% quicker in javascript.
- gengkev 8y agoWon't this calculation overflow to +Infinity in JavaScript after a while? On the other hand, Python will try to compute the actual result using arbitrary precision integers, which is that's slower.
- deleted 8y ago[deleted]