SwitchVsIF

Benchmark created by udeleng on


Description

Switch vs If-Else

Setup

function testSwitch(S, count) {
      for (var j = 0; j < count; j++) {
            switch (S.charAt(0)) {
                case 'A': 
                    break;
                case 'C': 
                    break;
                case 'G': 
                    break;
                case 'T': 
                    break;
            }
      }
    }
    
    function testIfElse(S, count) {
      for (var j = 0; j < count; j++) {
        if (S.charAt(0) === 'A') {
        } else if (S.charAt(0) === 'C') {
        } else if (S.charAt(0) === 'G') {
        } else if (S.charAt(0) === 'T') {
        }
      }
    }

Test runner

Ready to run.

Testing in
TestOps/sec
testSwitch
testSwitch('A', 10000)
ready
testIfElse
testIfElse('A', 10000)
ready

Revisions

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

  • Revision 1: published by udeleng on