For those interested in the real efficiency savings ...
I re-ran my benchmarks (I had to!) in a slightly more controlled environment, under more fair, compartmentalized conditions, ensuring that new page-sessions were open for each set of tests. And I found that one of my previous results was not necessarily accurate. (It's possible that the statement was "accurate" under certain conditions. But, I couldn't say what those conditions would be.)
I had previously stated, there's also a significant efficiency advantage when calling prototyped methods versus non-prototyped methods. In my benchmarks, it ranges between 13.5% and 21.7%. And at the the of that statement, I had run several permutations of the tests. But, I have since been unable to show any consistent difference. I would be interested to see others' benchmarks under various conditions. However, I've run iterative tests under fresh window loads with a variety of object instantiation syntaxes, and this particular point has proven to be mistaken.
So, in general, given two objects:
var ClassA = function() {
}
ClassA.add = function(a,b) {
return a + b;
}
var a = new ClassA();
var ClassB = function() {
this.add = function(a,b) {
return a + b;
}
}
var b = new ClassB();
The following two calls are, according to my tests, of equivalent efficiency:
a.add(1,1);
b.add(1,1);
Possible explanation: This latest suite of tests dwarfs any difference in the method-call with other logic: a method wrapper for the benchmarking loop, modulo arithmetic to pick an object instance, and a incrementor (actually two, if you count the one running the benchmark loop), and the method logic itself (adding p1 + p2 and returning). However, if the difference is so easily dwarfed into total undectability, it's probably not worth noting.
The object instantiation cost is much more significant, yielding a 51% savings using the prototype (a 106% performance hit by not using prototype). An object helper class, a bit simpler than the one Jeff Mott posted, shows no significant efficiency difference. And Jeff's example introduces about 15.8% efficiency during object instantiation over using the prototype directly (not sure where this efficiency hit could be occurring -- haven't really studied the code). I would estimate that the efficiency gap widens as the class methods become larger. Since I don't know where the efficiency hole in Jeff's code is, I can't say what would widen or shrink that gap.
I haven't looked at any of these in terms of memory consumption. And all benchmarks were performed in Chrome on OS X. Based previous benchmarks for different constructs (such as array creation), I am assuming that the results are similar, with slightly varying magnitude/significance.
So, stefan2 ... If you're attempting to perform hundreds of thousands of object instantiations per second, definitely use prototype. If you're instantiating a bunch of objects (even in the millions) all at once and then just calling their methods at a high rate, you're probably OK either way. But, you may run into memory problems in you have a lot of bulky objects, objects with many and/or large methods.
Find a system like Jeff's. De-obfuscate it, if you need to. (It seems obfuscated to me.) And find that tiny 15% efficiency hole if it's causing you any trouble (it probably won't).
... that was fun.