Typeof vs raw accessor 2
Date tested:
4 years ago
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:86.0) Gecko/20100101 Firefox/86.0
Test name
Executions per second
typeof function
15757050.0 Ops/sec
typeof object
0.0 Ops/sec
raw
107775720.0 Ops/sec
Benchmark definition (click to collapse):
Script Preparation code:
var data = { get: function() { if (Math.random() < 0.000000001) { console.log(5); } } }; var fn = function() { if (Math.random() < 0.000000001) { console.log(5); } }
Tests:
typeof function
var d1 = Math.random() > 0.5 ? data : fn; var d2 = d1 === data ? fn : data; typeof d1 === 'function' ? d1() : d1.get(); typeof d2 === 'function' ? d2() : d2.get();
typeof object
var d1 = Math.random() > 0.5 ? data : fn; var d2 = d1 === data ? fn : data; typeof d1 === 'object' ? d1() : d1.get(); typeof d2 === 'object' ? d2() : d2.get();
raw
data.get(); fn();
Open this result on MeasureThat.net