Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lookup table vs if statement
(version: 0)
Comparing performance of:
Lookup vs if else
Created:
3 years ago
by:
Guest
Jump to the latest result
Tests:
Lookup
Object.prototype.add = function (){ const object = Object.assign(this); const keys = Object.keys(object); let index = 0; const loopup = { 'object': function(arr){ const array = Object.values(arr); for(let o = 0, l = array.length; o < l; o++){ if(typeof(array[o]) === 'number'){ object[keys[index]] += array[o]; index++; } if(index === keys.length) break; }; }, 'number': function(number){ object[keys[index]] += number; index++; } } for(let i = 0, length = arguments.length; i < length; i++) { loopup[typeof(arguments[i])](arguments[i]) if(index === keys.length) break; } return object; }; const AddToObject = {"x": 121, "y": 122, "z": 500, p: 500, l: 69, j: 420}.add(900000,{x:6900,z:9000}, [5000000,123,123]);
if else
Object.prototype.add = function (){ const object = Object.assign(this); const keys = Object.keys(object); let index = 0; for(let i = 0, length = arguments.length; i < length; i++) { const type = typeof(arguments[i]) if(type === 'object'){ const array = Object.values(arguments[i]); for(let o = 0, l = array.length; o < l; o++){ if(typeof(array[o]) === 'number'){ object[keys[index]] += array[o]; index++; } if(index === keys.length) break; }; } else if(type === 'number') { object[keys[index]] += arguments[i]; index++; } if(index === keys.length) break; } return object; }; const AddToObject = {"x": 121, "y": 122, "z": 500, p: 500, l: 69, j: 420}.add(900000,{x:6900,z:9000}, [5000000,123,123]);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lookup
if else
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:138.0) Gecko/20100101 Firefox/138.0
Browser/OS:
Firefox 138 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lookup
4586976.5 Ops/sec
if else
5665081.0 Ops/sec
Related benchmarks:
Which operator is faster for indexOf ( '>' vs '===' ) is faster?
Which equals operator (== vs ===) is faster? check for null
Testing for false vs undefined vs == null vs hasOwnProperty vs hasOwn for undefined member
Which comparison operator (> vs ===) is faster?
Which comparison operator (> vs === vs !truthy) is faster?
Comments
Confirm delete:
Do you really want to delete benchmark?