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
function rndFieldName() {
return 'a' + Math.floor(Math.random()*999).toString(16);
}
function createWatch1(last) {
var field = rndFieldName();
var obj = {};
obj[field] = 1;
return (last.next = {
obj: obj,
lastValue: 1,
field: field,
next: null
});
}
function createWatch2(last) {
var field = rndFieldName();
var getter = new Function('s', 'return s.'+field);
var obj = {};
obj[field] = 1;
return (last.next = {
obj0: obj, lastValue0: 1, field0: field, getter0:getter,
obj1: obj, lastValue1: 1, field1: field, getter1:getter,
obj2: obj, lastValue2: 1, field2: field, getter2:getter,
obj3: obj, lastValue3: 1, field3: field, getter3:getter,
obj4: obj, lastValue4: 1, field4: field, getter4:getter,
obj5: obj, lastValue5: 1, field5: field, getter5:getter,
obj6: obj, lastValue6: 1, field6: field, getter6:getter,
obj7: obj, lastValue7: 1, field7: field, getter7:getter,
obj8: obj, lastValue8: 1, field8: field, getter8:getter,
obj9: obj, lastValue9: 1, field9: field, getter9:getter,
next: null
});
}
function createWatch3(last) {
var field = rndFieldName();
var getter = new Function('s', 'return s.'+field);
var obj = {};
obj[field] = 1;
return (last.next = {
obj0: obj, lastValue0: 1, field0: field, getter0:getter,
obj1: obj, lastValue1: 1, field1: field, getter1:getter,
obj2: obj, lastValue2: 1, field2: field, getter2:getter,
obj3: obj, lastValue3: 1, field3: field, getter3:getter,
obj4: obj, lastValue4: 1, field4: field, getter4:getter,
next: null
});
}
var head1 = createWatch1({});
var current = head1;
for(var i = 1; i < 10000; i++) {
current = createWatch1(current);
}
var head2 = createWatch2({});
var current = head2;
for(var i = 1; i < 1000; i++) {
current = createWatch2(current);
}
var head4 = createWatch3({});
var current = head4;
for(var i = 1; i < 2000; i++) {
current = createWatch2(current);
}
///////////////////////////////////////
function Watch1(previous) {
if (previous) previous.next = this;
this.field = rndFieldName();
this.obj = {};
this.lastValue = 1;
this.getter = new Function('c', 'return c.' + this.field);
this.obj[this.field] = this.lastValue;
this.check = Watch1.prototype.check;
}
Watch1.prototype.check = function() {
if (this.obj[this.field] !== this.lastValue) throw "DIRTY";
return this.next;
}
var head3 = new Watch1();
var current = head3;
for(var i = 1; i < 10000; i++) {
current = new Watch1(current);
}
///////////////////////////////////////
var size = 10000;
var objs = new Array(size);
var objFields = new Array(size);
var lastValues = new Array(size);
for(var i = 0; i < size; i++) {
var obj = objs[i] = {};
objFields[i] = 'a' + Math.floor(Math.random()*999).toString(16);
lastValues[i] = obj[objFields[i]] = 1;
}
Ready to run.
Test | Ops/sec | |
---|---|---|
dirtyCheck1 |
| ready |
dirtyCheck2 |
| ready |
dirtyCheck3 |
| ready |
| ready | |
function getter |
| ready |
Watch class |
| ready |
Watch Class method |
| ready |
Watch class getter |
| ready |
dirtyCheck1 if |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.