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:
one year ago
by:
Registered User
Go 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:
one year 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
getter
70K/s
instance property
48K/s
instanceof
34K/s
View exact numbers
Test name
Executions per second
✓
getter
69,724 Ops/sec
instance property
48,438 Ops/sec
instanceof
33,823 Ops/sec
Related benchmarks
Instanceof vs string comparison vs property checking vs constructor comparison
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?