I’m working on some fast looping for a project, and I decided to throw together a simple test to see how the performance varied when comparing runnning a more complex inner loop, vs. running several simple inner loops. Here is the jsperf for it:
http://jsperf.com/nested-fors-vs-iterative-fors
I’m surprised at how significant the difference appears to be.
Can anyone either point out why my test is bad (which may well be the case), or explain why the performance difference.
Thanks!
idb
I don’t know why you need underscore.js and jQuery for this. I’ve written a non-library version that compares:
The performance of each is pretty similar.
I think your issue is that the first case is 100 anonymous functions making 10 calls each. The second is 1,000 anonymous functions making one call each. The overhead is likely in creating the anonymous functions (though I have not looked at the related internal parts of the libraries being used).