Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
simple instanceof vs. getter vs. instance property
(version: 2)
Compare the basic performance of different ways of checking whether a given item is an instance of a specific class.
Comparing performance of:
instanceof vs getter vs instance property
Created:
9 months ago
by:
Registered User
Jump to the latest result
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);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
instanceof
getter
instance property
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
9 months ago
)
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/OS:
Chrome 138 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
instanceof
33822.8 Ops/sec
getter
69723.6 Ops/sec
instance property
48438.2 Ops/sec
Related benchmarks:
Instanceof vs string comparison vs property checking vs constructor comparison
Instanceof vs string comparison vs property checking vs constructor comparison 2
isEmpty tests
InstanceOf vs String type 2
instanceof vs string
typeof vs instanceof vs constructor
instanceof vs property in
instanceof vs manual checking
typeof vs instanceof vs constructor equality check
Comments
Confirm delete:
Do you really want to delete benchmark?