4 ms·
This appears to be micro-benchmarking the result of incrementing an integer by calling a function that calls a function nested in a bunch of object properties,
by forgotusername 16y ago
This appears to be micro-benchmarking the result of incrementing an integer by calling a function that calls a function nested in a bunch of object properties, vs. the same, but the called function lives in a closure.
Moral of the story? Perhaps, "make local aliases for objects used in performance-critical loops." Nothing new here.
Certainly not a good argument for one style of JavaScript library over the other (which seems to be the aim).
- bcrescimanno 16y agoWhat's really unfortunate is that this appears to be deliberately misleading. The writer of the test is either acting maliciously or doesn't have nearly enough understanding of how Javascript works to be making such an assertion. Sad to see this kind of silliness on HN.
- lucisferre 16y agoCould you be specific about what was deliberately misleading? You've made the assertion but didn't specify what you were referring to. Sad to see that kind of silliness on HN.
- bcrescimanno 16y agoIt's deliberately misleading to say that jQuery and other libraries use a pattern where (internal to the library) there are constant, deep chain lookups. The entire "problem" can be easily "fixed" with the solution above--cache local references so you're not doing deep-lookups constantly (which, if you look at the source of the referenced libraries, you won't find). As I said; it's either deliberately misleading--or the author's understanding of javascript is too limited as to be making claims that "jQuery and other libraries could have been 98% faster." A comment, by the way, which was later modified to state "if you are not a JavaScript Ninja your framework code could have been up to 98% faster." Sorry, I don't file that knowledge under "Javascript Ninja" knowledge--and moreover, the original comment was designed to say, "My library is faster / better than all of these popular libraries." [Edit] To my (admittedly cynical at times) that adds up to deliberately misleading.
- DominikGuzei 16y agoHey there, I changed the introduction on jsperf to reflect the awesome solutions that were posted afterwards! nevertheless it shows that if you don't keep those rules in mind all the time you might end up with very slow code. Thanks for your comment though!
- rhizome 16y agoIn the future you might consider only putting down words that you're willing to stand behind.
- TheBoff 16y agoIf you read the comments, it turns out that he's not really aiming to show anything, just experimenting. It's just interesting to know quite how severe the costs of global namespace lookups can be, for me.
- bcrescimanno 16y agoThe original description of the test had other implications--implications which have now been removed.