Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
switch case vs jump table vs bounce pattern vs ternary
(version: 0)
Comparing performance of:
switch case vs jump table vs bounce patttern vs ternary
Created:
3 years ago
by:
Guest
Jump to the latest result
Tests:
switch case
function thing(e) { switch (e) { case 0: return "0"; case 1: return "1"; case 2: return "2"; case 3: return "3"; } } for (let e = 0; 1e5 > e; e++) for (let e = 0; "3" != thing(e); e++) ;
jump table
function one() { return "0"; } function two() { return "1"; } function three() { return "2"; } function four() { return "3"; } let jumpTable = [ one, two, three, four ]; for (let a = 0; 1e5 > a; a++) for (let a = 0; "3" != jumpTable[a](); a++) ;
bounce patttern
function bounce(x) { if (x === 0) { return "0"; } if (x === 1) { return "1"; } if (x === 2) { return "2"; } if (x === 3) { return "3"; } } for (let e = 0; 1e5 > e; e++) for (let e = 0; "3" != bounce(e); e++) ;
ternary
function bounce(x) { return 0 === x ? "0" : 1 === x ? "1" : 2 === x ? "2" : 3 === x ? "3" : ""; } for (let e = 0; 1e5 > e; e++) for (let e = 0; "3" != bounce(e); e++) ;
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
switch case
jump table
bounce patttern
ternary
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
5 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36 Edg/142.0.0.0
Browser/OS:
Chrome 142 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
switch case
2708.2 Ops/sec
jump table
597.3 Ops/sec
bounce patttern
2664.4 Ops/sec
ternary
3189.8 Ops/sec
Related benchmarks:
Negation vs normal boolean value
.filter(Boolean) vs .filter(e => e)
lodash reverse vs native Array.prototype.reverse
Ternary operator vs String Interpolation
Switch/case vs indexOf
Comments
Confirm delete:
Do you really want to delete benchmark?