Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
JS class instanceof vs key in
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Browser:
Chrome 133
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
instanceof
39211.1 Ops/sec
key in
39992.2 Ops/sec
Script Preparation code:
const fooKey = Symbol('fooSymbol') class Foo { constructor(value) { this[fooKey] = true this.value = value } } let arr; function prepare() { arr = Array.from({length:1000}) for (let i = 0; i < arr.length; i++) { arr[i] = new Foo(i) } } function runInstanceof() { prepare(); const match = arr.every((foo) => foo instanceof Foo); if (!match) throw new Error('fail!'); } function runKeyIn() { prepare(); const match = arr.every((foo) => fooKey in foo); if (!match) throw new Error('fail!'); }
Tests:
instanceof
runInstanceof()
key in
runKeyIn()