class-vs-proto

Benchmark created on


Setup

function P(t) {this.t = t}
P.prototype.m = function(i) {
  if (i > this.t) {
    this.t = i;
  }
}

function P1(t) {
	P.call(this, t)
}

Object.setPrototypeOf(P1.prototype, P.prototype)

class C {
	constructor(t) {
		this.t = t
	}
  m(i) {
    if (i > this.t) {
       this.t = i;
    }
  }
}

class C1 extends C {
	constructor(t) {
		super(t)
	}
}

Test runner

Ready to run.

Testing in
TestOps/sec
proto
new P(Math.random()).m(Math.random());
ready
class
new C(Math.random()).m(Math.random());
ready
proto child
new P1(Math.random()).m(Math.random());
ready
class child
new C1(Math.random()).m(Math.random());
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.