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
Testing various techniques for creating getters / setters in JavaScript.
Testing a variation of 'Combined getter / setter method'. I had heard that using the 'arguments' object requires a heavy performance hit
<script>
var global = this;
(function() {
global.obj1 = {
start: {
row: 1,
col: 1
}
};
global.obj2 = {
_start: {
row: 1,
col: 1
},
start: function(val) {
if (val) {
this._start = val
} else {
return this._start;
}
}
};
global.obj4 = {
_start: 1,
start: function(val) {
if (val) {
this._start = val
} else {
return this._start;
}
}
};
global.obj5 = {
_start: {
row: 1,
col: 1
},
start: function(val) {
if (val) {
this._start = val
} else {
return this._start;
}
},
modifyRow: function(delta) {
this.row += delta;
}
};
global.obj6 = {
_start: {
row: 1,
col: 1
},
start: function(val) {
if (val) {
this._start = val
} else {
return this._start;
}
},
modify: function(key, delta) {
this[key] += delta;
}
};
global.obj7 = {
_start: {
row: 1,
col: 1
},
start: function(val) {
if (val) {
this._start = val
} else {
return this._start;
}
},
modifyRow: function(delta) {
this.row = this.row + delta;
}
};
function Cell() {
this._start = {
row: 1,
col: 1
}
}
Cell.prototype = {
start: function(val) {
if (val) {
this._start = val
} else {
return this._start;
}
},
modifyRow: function(delta) {
this.row = this.row + delta;
},
modifyCol: function(delta) {
this.col = this.col + delta;
}
};
global.obj8 = new Cell();
global.obj9 = new Cell();
function Cell2() {
this._start = {
row: 1,
col: 1
}
}
Cell2.prototype = {
start: function(val) {
if (val) {
this._start.row = val.row;
this._start.col = val.col;
} else {
return this._start;
}
},
modifyRow: function(delta) {
this.row = this.row + delta;
},
modifyCol: function(delta) {
this.col = this.col + delta;
}
};
global.obj10 = new Cell2();
})();
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
Direct property change |
| ready |
Getter/setter method |
| ready |
Direct property change w/body |
| ready |
Primitive |
| ready |
Modify row |
| ready |
Modify [key] |
| ready |
Modify row without sugar |
| ready |
Using an object |
| ready |
Set all object |
| ready |
Set all object (using props) |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.