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
<script>
//1
var circleFns = {
area: function() {
return Math.PI * this.radius * this.radius;
},
grow: function() {
this.radius++;
},
shrink: function() {
this.radius--;
}
}
//2
var asCircle = function() {
this.area = function() {
return Math.PI * this.radius * this.radius;
};
this.grow = function() {
this.radius++;
};
this.shrink = function() {
this.radius--;
};
}
//3
var asCircleCached = (function() {
var area = function() {
return Math.PI * this.radius * this.radius;
};
var grow = function() {
this.radius++;
};
var shrink = function() {
this.radius--;
};
return function() {
this.area = area, this.grow = grow, this.shrink = shrink;
}
})();
var asCircleCachedPassedObj = (function() {
var area = function() {
return Math.PI * this.radius * this.radius;
};
var grow = function() {
this.radius++;
};
var shrink = function() {
this.radius--;
};
return function(obj) {
var proto = obj.prototype;
proto.area = area, proto.grow = grow, proto.shrink = shrink;
}
})();
var asCircleCachedPassedProto = (function() {
var area = function() {
return Math.PI * this.radius * this.radius;
};
var grow = function() {
this.radius++;
};
var shrink = function() {
this.radius--;
};
return function(proto) {
proto.area = area, proto.grow = grow, proto.shrink = shrink;
}
})();
//4
Function.prototype.curry = function(arg, context) {
var f = this;
return function () {
var args = [arg];
for (var i = 0, len = arguments.length; i < len; i += 1) {
args[i + 1] = arguments[i];
}
return f.apply(context || this, args);
};
};
//4
var asCircleCachedAndCurried = (function() {
var area = function() {
return Math.PI * this.radius * this.radius;
};
var grow = function(growBy) {
this.radius += growBy;
};
var shrink = function(shrinkBy) {
this.radius -= shrinkBy;
};
return function(options) {
this.area = area, this.grow = grow.curry(options['growBy']), this.shrink = shrink.curry(options['shrinkBy'])
}
})();
//5
var asCircleWithOptions = function(options) {
this.area = function() {
return Math.PI * this.radius * this.radius;
};
this.grow = function() {
this.radius += options.growBy;
};
this.shrink = function() {
this.radius -= options.shrinkBy;
};
}
//6
var CircleComponent = function(circle, options) {
circle.area = function() {
return Math.PI * circle.radius * circle.radius;
};
circle.grow = function() {
circle.radius += options.growBy;
};
circle.shrink = function() {
circle.radius -= options.shrinkBy;
};
};
//set up test constructor
var CircularObject = function(radius) {
this.radius = radius
};
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
old style |
| ready |
new style |
| ready |
new style w/ caching |
| ready |
new style w/caching and options |
| ready |
new style uncached w/options |
| ready |
Direct assignment function w/ options |
| ready |
cached passed Object |
| ready |
cached passed prototype |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.