Try/Catch Block Loop Performance Comparison (v13)

Revision 13 of this benchmark created by Amio on


Description

Measuring the performance implications of a try/catch block used with loops and functions.

Test runner

Ready to run.

Testing in
TestOps/sec
Plain Loop
for (var i = 0; i < 500000; i++) {
  var n = 1;
}
ready
Try/Catch Block Outside Loop
try {
  for (var i = 0; i < 500000; i++) {
    var n = 1;
  }
} catch (e) {}
ready
Try/Catch Block Inside Loop
for (var i = 0; i < 500000; i++) {
  try {
    var n = 1;
  } catch (e) {}
}
ready
try catch present
try {

} catch (e) {}

for (var i = 0; i < 500000; i++) {
  var n = 1;
}
ready
Try/Catch Block Outside Function
try {
  (function(){
    for (var i = 0; i < 500000; i++) {
      var n = 1;
    }
  })()
} catch (e) {}
ready

Revisions

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