Try/Catch performance overhead (v27)

Revision 27 of this benchmark created on


Description

Using try/catch inside of functions that allocate lots of variables introduces significant overhead. See this discussion related to node.js https://groups.google.com/forum/#!topic/nodejs-dev/E-Re9KDDo5w

Interestingly, other js engines don't have this overhead. All test runs have pretty uniform performance. But they are also significantly slower than the v8 control case.

Test runner

Ready to run.

Testing in
TestOps/sec
control - no try/catch
function test(j) {
  var i, s = 0;
  for (i = 0; i < j; i++) s = i;
  for (i = 0; i < j; i++) s = i;
  for (i = 0; i < j; i++) s = i;
  for (i = 0; i < j; i++) s = i;
  return s;
}
test(100000);
 
ready
try/catch inside function
function test(j) {
  try {
    var i, s = 0;
    for (i = 0; i < j; i++) s = i;
    for (i = 0; i < j; i++) s = i;
    for (i = 0; i < j; i++) s = i;
    for (i = 0; i < j; i++) s = i;
    return s;
  } catch (e) {}
}
test(100000);
 
ready
try/catch outside function
function test(j) {
  var i, s = 0;
  for (i = 0; i < j; i++) try {s = i;} catch (e) {}
  for (i = 0; i < j; i++) try {s = i;} catch (e) {}
  for (i = 0; i < j; i++) try {s = i;} catch (e) {}
  for (i = 0; i < j; i++) try {s = i;} catch (e) {}
  return s;
}
test(100000);
 
ready

Revisions

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