Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
if vs switch case
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36
Browser:
Chrome 129
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
switch case
158.2 Ops/sec
jump table
157.3 Ops/sec
Tests:
switch case
function thing(j) { switch(j) { case 0: case 1: case 2: case 3: return 1; case 10: case 11: case 12: case 13: return 2; case 24: case 25: case 26: case 27: return 3; default: return 0; } } let sum = 0 for(let i = 0; i < 100000; i++) { for(let j = 0; j < 32; j++) { sum += thing(j); } } console.log(sum);
jump table
function thing(j) { if(j == 0) return 1; if(j == 1) return 1; if(j == 2) return 1; if(j == 3) return 1; if(j == 10) return 2; if(j == 11) return 2; if(j == 12) return 2; if(j == 13) return 2; if(j == 24) return 3; if(j == 25) return 3; if(j == 26) return 3; if(j == 27) return 3; return 0; } let sum = 0 for(let i = 0; i < 100000; i++) { for(let j = 0; j < 32; j++) { sum += thing(j); } } console.log(sum);