loop breaking

Benchmark created by bradleymeck on


Description

switches labels break loops and state variables oh my!

Setup

function labeledBreak() {
      var state = 'a';
      loop:
      for(;;) {
        switch (state) {
          case 'a': state = 'b'; break;
          case 'b': state = 'c'; break;
          case 'c': state = 'd'; break;
          case 'd': state = 'e'; break loop;
        }
      }
    }
    function stateVariableBreak() {
      var state = 'a';
      for(;;) {
        switch (state) {
          case 'a': state = 'b'; break;
          case 'b': state = 'c'; break;
          case 'c': state = 'd'; break;
          case 'd': state = 'e'; break;
        }
        if (state = 'e') break;
      }
    }
    function naturalBreak() {
      var state = 'a';
      for(; state != 'e' ;) {
        switch (state) {
          case 'a': state = 'b'; break;
          case 'b': state = 'c'; break;
          case 'c': state = 'd'; break;
          case 'd': state = 'e'; break;
        }
      }
    }
    function control() {
      for(var i = 0; i < 5; i++) {}
    }

Test runner

Ready to run.

Testing in
TestOps/sec
labeled break
labeledBreak()
ready
state variable break
stateVariableBreak()
ready
natural break
naturalBreak()
ready
control
control()
ready

Revisions

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

  • Revision 1: published by bradleymeck on