Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Int switch vs str switch vs int if-else vs str if-else vs int object-key vs str object-key v2
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (iPhone; CPU iPhone OS 18_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.2 Mobile/15E148 Safari/604.1
Browser:
Mobile Safari 18
Operating system:
iOS 18.2
Device Platform:
Mobile
Date tested:
one year ago
Test name
Executions per second
Int switch
584695.8 Ops/sec
str switch
527985.6 Ops/sec
int if-else
222489.5 Ops/sec
str if-else
185360.0 Ops/sec
int object-key
526102.8 Ops/sec
str object-key
355381.2 Ops/sec
Script Preparation code:
var intKey = [0,1,2,3,4,5,6,7,8,9,10] var intObj = {0:'zero', 1:'one', 2:'two', 3:'three', 4:'four', 5:'five', 6:'six', 7:'seven', 8:'eight', 9:'nine', 10:'ten'} var strKey = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10'] var strObj = {'0':'zero', '1':'one', '2':'two', '3':'three', '4':'four', '5':'five', '6':'six', '7':'seven', '8':'eight', '9':'nine', '10':'ten'}
Tests:
Int switch
res=[] for(let i = 0; i<=10; i++){ switch(intKey[i]){ case 0: res.push(intObj[0]) break case 1: res.push(intObj[1]) break case 2: res.push(intObj[2]) break case 3: res.push(intObj[3]) break case 4: res.push(intObj[4]) break case 5: res.push(intObj[5]) break case 6: res.push(intObj[6]) break case 7: res.push(intObj[7]) break case 8: res.push(intObj[8]) break case 9: res.push(intObj[9]) break case 10: res.push(intObj[10]) break } }
str switch
res=[] for(let i = 0; i<=10; i++){ switch(strKey[i]){ case '0': res.push(strObj['0']) break case '1': res.push(strObj['1']) break case '2': res.push(strObj['2']) break case '3': res.push(strObj['3']) break case '4': res.push(strObj['4']) break case '5': res.push(strObj['5']) break case '6': res.push(strObj['6']) break case '7': res.push(strObj['7']) break case '8': res.push(strObj['8']) break case '9': res.push(strObj['9']) break case '10': res.push(strObj['10']) break } }
int if-else
res=[] for(let i = 0; i<=10; i++){ if(intKey[i]==0){ res.push(intObj[0]) }else if(intKey[i]==1){ res.push(intObj[1]) }else if(intKey[i]==2){ res.push(intObj[2]) }else if(intKey[i]==3){ res.push(intObj[3]) }else if(intKey[i]==4){ res.push(intObj[4]) }else if(intKey[i]==5){ res.push(intObj[5]) }else if(intKey[i]==6){ res.push(intObj[6]) }else if(intKey[i]==7){ res.push(intObj[7]) }else if(intKey[i]==8){ res.push(intObj[8]) }else if(intKey[i]==9){ res.push(intObj[9]) }else if(intKey[i]==10){ res.push(intObj[10]) } }
str if-else
res=[] for(let i = 0; i<=10; i++){ if(strKey[i]==0){ res.push(strObj[0]) }else if(strKey[i]==1){ res.push(strObj[1]) }else if(strKey[i]==2){ res.push(strObj[2]) }else if(strKey[i]==3){ res.push(strObj[3]) }else if(strKey[i]==4){ res.push(strObj[4]) }else if(strKey[i]==5){ res.push(strObj[5]) }else if(strKey[i]==6){ res.push(strObj[6]) }else if(strKey[i]==7){ res.push(strObj[7]) }else if(strKey[i]==8){ res.push(strObj[8]) }else if(strKey[i]==9){ res.push(strObj[9]) }else if(strKey[i]==10){ res.push(strObj[10]) } }
int object-key
res=[] for(let i = 0; i<=10; i++){ res.push(intObj[intKey[i]]) }
str object-key
res=[] for(let i = 0; i<=10; i++){ res.push(strObj[strKey[i]]) }