Exceptions for flow-control (v2)

Revision 2 of this benchmark created on


Description

Tests if breaking from a nested loop is faster using a "try/catch" block or a break statement to a label.

Preparation HTML

<script>
  var i, j, target = 11;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Try/catch
try {
 for (i = 0; i < 10; i++) {
  for (j = 0; j < 10; j++) {
   if ([i, j].join('') == target) {
    throw "found";
   }
  }
 }
} catch (e) {}
ready
Break label
found: for (i = 0; i < 10; i++) {
 for (j = 0; j < 10; j++) {
  if ([i, j].join('') == target) {
   break found;
  }
 }
}
ready

Revisions

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