jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
The choice between instance and prototype methods is not as simple as putting them inside or outside the constructor. In any real environment, the method is going to have to access properties of the object (otherwise, why is it a method and not a standalone function?). Given that expectation, a prototyped method incurs the additional cost of referencing object properties as "this.property" rather than simply "property" via closure.
We also probably won't be creating new object as often as calling their methods, and this test case is aimed at method definition anyway, so we should move the "new" outside the loop to get a better sense of the actual method call overhead of the two approaches, without being skewed by the object instantiation overhead.
Ready to run.
Test | Ops/sec | |
---|---|---|
Instance |
| ready |
Prototype |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.