Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
isArray vs instanceof vs Symbol.iterator
Symbol.iterator also matches TypedArray, Map, and such
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:121.0) Gecko/20100101 Firefox/121.0
Browser:
Firefox 121
Operating system:
Linux
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
isArray
3999275.5 Ops/sec
instanceof
2742975.5 Ops/sec
Symbol.iterator
1747799.2 Ops/sec
Script Preparation code:
var types = { array: [1,2,3], number: 123, string: '123', map: new Map([[1,1],[2,2],[3,3]]), set: new Set([1,2,3]), buffer: new ArrayBuffer([1,2,3]), boolean: true, arrow: () => {}, function: function () {}, object: {}, u8: new Uint8Array(), u16: new Uint16Array(), u32: new Uint32Array(), i8: new Int8Array(), i16: new Int16Array(), i32: new Int32Array() } var keys = Object.keys(types)
Tests:
isArray
keys.map(key => Array.isArray(types[key]) === true)
instanceof
keys.map(key => (types[key] instanceof Array) === true)
Symbol.iterator
keys.map(key => types[key][Symbol.iterator] !== undefined)