An objective way to benchmark memory/speed of different Inheritance Patterns in JavaScript?
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.
W开发者_如何学编程hat 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!
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.
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.
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.
Not sure whether this will help or not but check dyna trace does some nice job for giving numbers.
精彩评论