Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
typeof vs cached typeof
is it worth caching a typeof result in a loop
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
Browser:
Chrome 135
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
uncached typeof
612K/s
cached typeof
589K/s
View exact numbers
Test name
Executions per second
✓
uncached typeof
611,517 Ops/sec
cached typeof
589,293 Ops/sec
Script Preparation code:
var arr = [null,true,123,'',{},[]];
Tests:
uncached typeof
for(let n = 0; n < 100; n++) { arr.map((i) => { if (typeof i !== 'XXX') { return typeof i; } }); }
cached typeof
for(let n = 0; n < 100; n++) { arr.map((i) => { const typeOfI = typeof i; if (typeOfI !== 'XXX') { return typeOfI; } }); }