if statements versus ternary

Benchmark created on


Setup

const rand = Math.random() < 0.5;
let c = "";

Test runner

Ready to run.

Testing in
TestOps/sec
if statements
c += 12;
if (rand) c += ":";
c += 34;
if (rand) c += ":";
c += 56;
c += "." + 78;
ready
ternary
c += 12;
c += (rand) ? ":" : "";
c += 34;
c += (rand) ? ":" : "";
c += 56;
c += "." + 78;
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.