Joined October 2013
·

Petka Antonov

Helsinki, Finland
·
·

@dtao I am trying actually trying to defend your point. Many people shrug off object creation because they are "not creating that many objects anyway". Anyway, in object creation you have O(n) vs O(1) so there is no fair benchmark. If you benchmark a class of say, 25 methods, you will easily get like 10000x difference. And again many people only benchmark with one method (so they compare O(N) to O(1) with N=1, lol).

My point is that it should already be obvious to everyone that the object creation will be extremely slow when methods are re-recreated instead of placed on prototype.

This opens up comparison of method calls rather than object creation, where I am again trying to explain that 1.5x difference is not what it looks like and there is much bigger difference in practice even between method calls of "prototype class" vs "closure class"

You should see my reddit comment http://www.reddit.com/r/javascript/comments/1nnkfe/the_prototype_is_your_friend_if_you_care_about/ccm0rw6

In the fixed jsperf, prototype method invocation is "only" 1.5x faster. Even if we ignore for a second that this difference is huge for such a low level operation, we cannot look at the 1.5x at face value because the difference comes from the ability to do inlining.

Achievements
108 Karma
0 Total ProTip Views