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/605.1.15 (KHTML, like Gecko) Version/18.5 Safari/605.1.15
Browser:
Safari 18
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
9 months ago
Test name
Executions per second
instance
81562.4 Ops/sec
getter
96214.4 Ops/sec
instance property
85101.6 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);