Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
isfn vs switch
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/119.0.0.0 Safari/537.36
Browser:
Chrome 119
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
isCollection1
2756192.0 Ops/sec
isCollection2
7008870.0 Ops/sec
Script Preparation code:
var isMap = (val) => val?.constructor?.name === 'Map' var isSet = (val) => val?.constructor?.name === 'Set' var isWeakMap = (val) => val?.constructor?.name === 'WeakMap' var isWeakSet = (val) => val?.constructor?.name === 'WeakSet' var isCollection1 = (val) => isMap(val) || isSet(val) || isWeakMap(val) || isWeakSet(val) var isCollection2 = (val) => { switch(val?.constructor?.name) { case 'Map': case 'Set': case 'WeakMap': case 'WeakSet': return true default: return false } } console.log(isCollection1(new Set()), isCollection1(123)) console.log(isCollection2(new Set()), isCollection2(123))
Tests:
isCollection1
var a = isCollection1(new Set()) var b = isCollection1(123)
isCollection2
var a = isCollection2(new Set()) var b = isCollection2(123)