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
proto1 = { a: 1 }
proto2 = Object.create(proto1, { b: {value: 2 }})
proto3 = Object.create(proto2, { c: {value: 3 }})
proto4 = Object.create(proto3, { d: {value: 4 }})
// Constructor
function Foo(x, y) {
this.x = x
this.y = y }
Foo.prototype = Object.create(proto4)
Foo.prototype.get = function() { return [this.x, this.y] }
// Closured (flat)
function extend(target, source) {
for (var key in source)
target[key] = source[key]
return target }
function make_foo(x, y) {
// obviously a huge perf hit
var instance = extend({}, proto4)
instance.x = x
instance.y = y
instance.get = function(){ return [x, y] }
return instance }
// Cloning
var foo = Object.create(proto4)
foo.get = function() { return [this.x, this.y] }
function create_foo(x, y) {
var instance = Object.create(foo)
instance.x = x
instance.y = y
return instance }
// ad-hoc cloning
function make(proto) {
function Dummy(){}
Dummy.prototype = proto
return new Dummy }
function make_adhoc_foo(x, y) {
var instance = make(foo)
instance.x = x
instance.y = y
return instance }
// Changing the proto-chain
function setproto_foo(x, y) {
var instance = {}
instance.__proto__ = foo
instance.x = x
instance.y = y
return instance }
// Instances
var new_foo = new Foo(1, 1)
var closure_foo = make_foo(1, 1)
var cloned_foo = create_foo(1, 1)
var adhoc_foo = make_adhoc_foo(1, 1)
var slow_foo = setproto_foo(1, 1)
var z = 0, x
Ready to run.
Test | Ops/sec | |
---|---|---|
Creation (constructor) |
| ready |
Creation (closured) |
| ready |
Creation (cloning) |
| ready |
Creation (set proto-chain) |
| ready |
Slot access (constructor) |
| ready |
Slot access (closured) |
| ready |
Slot access (cloned) |
| ready |
Slot access (set proto) |
| ready |
Fallback slot access (constructor) |
| ready |
Fallback slot access (closured) |
| ready |
Fallback slot access (cloned) |
| ready |
Fallback slot access (set proto) |
| ready |
Slot creation (constructor) |
| ready |
Slot creation (closured) |
| ready |
Slot creation (cloned) |
| ready |
Slot creation (set proto) |
| ready |
Call shared (constructor) |
| ready |
Call shared (closured) |
| ready |
Call shared (cloned) |
| ready |
Call shared (set proto) |
| ready |
Creation (adhoc) |
| ready |
Slot access (adhoc) |
| ready |
Fallback slot access (adhoc) |
| ready |
Slot creation (adhoc) |
| ready |
Call shared (adhoc) |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.