bind or no bind

Benchmark created on


Setup

class Foo {
	foo(a) {
		this.a = a;
	}
	
	foo2(a) {
		this.a = a * 2;
	}
	
	foo3(a) {
		this.a = a * 3;
	}
	
	foo4(a) {
		this.a = a * 4;
	}
	
	foo5(a) {
		this.a = a * 5;
	}
	
	foo6(a) {
		this.a = a * 6;
	}
	
	foo7(a) {
		this.a = a * 7;
	}
}

class Bar {
	constructor() {
		this.foo = this.foo.bind(this);
		this.foo2 = this.foo2.bind(this);
		this.foo3 = this.foo3.bind(this);
		this.foo4 = this.foo4.bind(this);
		this.foo5 = this.foo5.bind(this);
		this.foo6 = this.foo6.bind(this);
		this.foo7 = this.foo7.bind(this);
		
	}
	
	foo(a) {
		this.a = a;
	}
	
	foo2(a) {
		this.a = a * 2;
	}
	
	foo3(a) {
		this.a = a * 3;
	}
	
	foo4(a) {
		this.a = a * 4;
	}
	
	foo5(a) {
		this.a = a * 5;
	}
	
	foo6(a) {
		this.a = a * 6;
	}
	
	foo7(a) {
		this.a = a * 7;
	}
}

Test runner

Ready to run.

Testing in
TestOps/sec
Create instanced with bounded method
let x = null;
for (let i = 0; i < 10000; i++) {
	x = new Bar();
}
ready
Create instanced without bounded method
let x = null;
for (let i = 0; i < 10000; i++) {
	x = new Foo();
}
ready

Revisions

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