instanceof performance

Benchmark created on


Setup

class X { constructor() { this.name = "X" } }
class Y { constructor() { this.name = "Y" } }
const data = Array.from({ length: 1000 }).map(() => Math.random() >= 0.5 ? new X() : new Y());

Test runner

Ready to run.

Testing in
TestOps/sec
instanceof
data.filter(i => i instanceof X).length
ready
string comparison
data.filter(i => i.name === "X").length
ready

Revisions

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