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; rv:145.0) Gecko/20100101 Firefox/145.0
Browser:
Firefox 145
Operating system:
Windows
Device Platform:
Desktop
Date tested:
5 months ago
Test name
Executions per second
uncached typeof
664507.6 Ops/sec
cached typeof
470383.7 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; } }); }