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
examining typeof(parameter) vs using arguments[] in constructor
<script>
Point1 = function (x, y) {
if (typeof (x) === 'number') {
this.x = x || 0;
this.y = y || 0;
} else if (typeof (x) === 'object') {
this.x = x[0] || x.x || 0;
this.y = x[0] || x.y || 0;
} else {
this.x = 0;
this.y = 0;
}
};
Point2 = function (x, y) {
if (arguments.length === 2) {
this.x = arguments[0] || 0;
this.y = arguments[1] || 0;
} else {
this.x = arguments[0][0] || arguments[0].x || 0;
this.x = arguments[0][1] || arguments[0].y || 0;
}
};
Point3 = function (x, y) {
this.x = x || 0;
this.y = y || 0;
}
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
examing param types |
| ready |
examine arguments object |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.