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/605.1.15 (KHTML, like Gecko) Version/18.6 Safari/605.1.15
Browser:
Safari 18
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
7 months ago
Test name
Executions per second
instanceof
273787.6 Ops/sec
key in
266796.3 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()