Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
simple instanceof vs. getter vs. instance property
Compare the basic performance of different ways of checking whether a given item is an instance of a specific class.
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/138.0.0.0 Safari/537.36
Browser:
Chrome 138
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
9 months ago
Test name
Executions per second
instance
44743.1 Ops/sec
getter
93345.6 Ops/sec
instance property
64859.0 Ops/sec
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
class ExampleClass { get isExampleGetter() { return true; } isExampleField = true; } const items = Array.from({ length: 10000 }, (_) => new ExampleClass());
Tests:
instanceof
let validCount = 0; for (const i of items) { if (i instanceof ExampleClass) { validCount += 1; } } console.log(validCount);
getter
let validCount = 0; for (const i of items) { if (i.isExampleGetter) { validCount += 1; } } console.log(validCount);
instance property
let validCount = 0; for (const i of items) { if (i.isExampleField) { validCount += 1; } } console.log(validCount);