Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
FAQ
Register
Log In
Run results for:
no loop, switch case vs bounce pattern vs ternary
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Browser:
Chrome 120
Operating system:
Windows
Device Platform:
Desktop
Date tested:
2 years ago
Benchmark engine:
Benchmark.js
ternary
819.7M/s
switch case
818.3M/s
bounce patttern
790.3M/s
View exact numbers
Test name
Executions per second
✓
ternary
819,653,120 Ops/sec
switch case
818,290,560 Ops/sec
bounce patttern
790,326,528 Ops/sec
Tests:
switch case
function thing(e) { switch (e) { case 0: return "0"; case 1: return "1"; case 2: return "2"; case 3: return "3"; default: return ""; } } thing(0), thing(2), thing(6)
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"; return "" } bounce(0), bounce(2), bounce(6)
ternary
function bounce(x) { return 0 === x ? "0" : 1 === x ? "1" : 2 === x ? "2" : 3 === x ? "3" : ""; } bounce(0), bounce(2), bounce(6)