views:

185

answers:

4

I often see arguments between Classical (faked via some library), Pseudo-Classical and Prototypal Inheritance mention "efficiency." However, I've never seen any data backing any of this kind of stuff up. Not to mention "efficiency" seems like an ambiguous word when it comes to a coding style, rather than an algorithm.

I'd like to do some tests to "benchmark" some of these patterns and libraries. This seems distinctly different than most algorithm or display benchmarks that I've seen in the past. What do you guys think are the important things to test, and what are the best ways to get those numbers reliably.

What I'm thinking currently:

  • Speed of instantiation (Time the creation of a few thousand objects using each pattern w/ identical functionality)
  • Memory usage (The only way I can think is to look at my memory in the task manager... is there a better way)
  • Speed of access to internal properties and methods (iteration timing again)
  • Speed of copies (iteration timing)
  • Lines of code (Peer reviewed best practice following examples with a count)

Any fallacies, additions, or objections? Anyone seen this data elsewhere?

Thanks!

+1  A: 

This may sound obvious: You'll need to keep in mind that each browser will give different results. It should be part of whatever matrix you create in your testing. Good luck.

darelf
Absolutely, I'll probably test the same list that most libraries claim to support. Thanks for the input, of course, though.
Alex Sexton
+1  A: 

I have not used it myself, but JSLitmus looks like the right tool for the job. Here is a benchmark of different inheritance methods using JSLitmus.

If you test for lines of code, and size does really matter to your benchmark (and size of javascript files does matter), then you should also test for the size of minified javascript files using YUI Coompressor.

For the memory usage benchmarks, I do not have any other idea than looking at task manager or top in Linux systems or the equivalent in Mac OS X (and you should test these too).

Apart from that: Good luck and please release the information retrieved by your benchmarks. And don't forget to include the test methods for reproduction of the values, so that any other interested programmers can peer-review your results.

Residuum
Great! This is a very helpful answer!
Alex Sexton
+1  A: 

There are some tests and numbers linked from this blog post.

Also make sure to read this article by John Resig on the accuracy of JavaScript time and how it affects performance benchmarks. If you don't end up using JSLitmus as Residuum suggested, make sure to still use adaptive test cycles.

Although I agree 100% with darelf's comment that you should test multiple browsers, you can get detail on memory and cpu usage in Chrome by pressing Shift+Esc.

Annie
Also a really great read with good info and tests. Thanks alot!
Alex Sexton
I think everyone did a pretty great job at answering this, but you knocked out both sides of the question pretty well. So bounty ho. Sorry to others. Thanks a ton.
Alex Sexton
+1  A: 

Not sure whether this will help or not but check dyna trace does some nice job for giving numbers.

Anil Namde
Yea, this definitely helps on the memory side of things. Thanks.
Alex Sexton