ifelse versus switch (v2)

Revision 2 of this benchmark created by Supercryptonite on


Description

Check performance of switch and if else with inline and referenced variables

Setup

var f, g, h;
    f = 0, g = 1, h = 2;

Test runner

Ready to run.

Testing in
TestOps/sec
If/Else inline
var v = 2;
if (v === 0) {} else if (v === 1) {} else if (v === 2) {}
ready
If/Else reference
var v = 2;
if (v === f) {} else if (v === g) {} else if (v === h) {}
ready
Switch inline
var v = 2;
switch (v) {
  case 0:
    break;
  case 1:
    break;
  case 2:
    break;
}
ready
Switch reference
var v = 2;
switch (v) {
  case f:
    break;
  case g:
    break;
  case h:
    break;
}
ready
Tenary inline (approx)
var v = 2;
var result = v === 0 ? true : v === 1 ? true : v === 2 ? true : false;
ready
Tenary reference (approx)
var v = 2;
var result = v === f ? true : v === g ? true : v === h ? true : false;
ready

Revisions

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

  • Revision 1: published on
  • Revision 2: published by Supercryptonite on