Instanceof

Benchmark created on


Setup

class Foo {
	id = 0
}

class Bar {
	id = 5
}

const list = [
	new Foo(),
	new Foo(),
	new Foo(),
	new Foo(),
	new Bar(),
	new Foo(),
	new Foo(),
	new Foo(),
	new Foo(),
	new Foo()
] 

Test runner

Ready to run.

Testing in
TestOps/sec
instanceof
for (let i = 0; i < list.length; i++) {
	if (list[i] instanceof Bar) {
		break
	}
}
ready
id equals x
for (let i = 0; i < list.length; i++) {
	if (list[i].id === 5) {
		break
	}
}
ready

Revisions

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