Try/Catch Cost In a Loop (v9)

Revision 9 of this benchmark created by Seth Holladay on


Description

How much does a try catch cost?

Setup

var obj = { a : 1, b : 2, c : 3, d : 4, e : 5 };

Test runner

Ready to run.

Testing in
TestOps/sec
Vanilla iteration
var prop, blah = '';
for (prop in obj) {
    blah += obj[prop];
}
ready
Iteration with external try/catch
var prop, blah = '';
try {
    for (prop in obj) {
        blah += obj[prop];
    }
}
catch (e) {
    console.log(' ');
}
ready
Iteration with internal try/catch
var prop, blah = '';
for (prop in obj) {
    try {
        blah += obj[prop];
    }
    catch (e) {
        console.log(' ');
    }
}
ready

Revisions

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