Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
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/121.0.0.0 Safari/537.36
Browser:
Chrome 121
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
2 years ago
Benchmark engine:
Benchmark.js
isCollection2
6.9M/s
isCollection1
2.7M/s
View exact numbers
Test name
Executions per second
✓
isCollection2
6,905,458 Ops/sec
isCollection1
2,745,661 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)