Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Switch vs. dictionary
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/128.0.0.0 Safari/537.36
Browser:
Chrome 128
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Switch
13827057.0 Ops/sec
If
7129559.0 Ops/sec
Script Preparation code:
var random = Math.floor(Math.random() * 20);
Tests:
Switch
switch (random) { case 0: random = -Math.PI; break; case 1: random = Math.EPSILON; break; case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: random = 1; break; case 10: case 11: case 12: random /= 5; break; case 13: case 14: case 15: case 16: case 17: random **= 2; break; case 18: random = 5; break; case 19: random = 28; break; case 20: random = 0; break; default: random = -1; break; }
If
const test = { 0: () => -Math.PI, 1: () => Math.EPSILON, 2: () => 1, 3: () => 1, 4: () => 1, 5: () => 1, 6: () => 1, 7: () => 1, 8: () => 1, 9: () => 1, 10: (rand) => rand / 5, 11: (rand) => rand / 5, 12: (rand) => rand / 5, 13: (rand) => rand ** 2, 14: (rand) => rand ** 2, 15: (rand) => rand ** 2, 16: (rand) => rand ** 2, 17: (rand) => rand ** 2, 18: () => 5, 19: () => 28, 20: () => 0, }; random = test[random]?.() || -1;