Try/Catch Block Loop Performance Comparison (v10)

Revision 10 of this benchmark created by Ashraf Samy Hegab on


Description

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

Test runner

Ready to run.

Testing in
TestOps/sec
Plain loop
for(var i = 0; i < 500; i++){
    var n = 1;
}
ready
Plain try/catch
try{
    for(var i = 0; i < 500; i++){
        var n = 1;
    }
}catch(e){}
ready
Function try/catch
try{
    var test = function()
    {
        for(var i = 0; i < 500; i++){
            var n = 1;
        }
    };
    test();
}catch(e){}
ready
Outside function try/catch
var test = function()
{
    for(var i = 0; i < 500; i++){
        var n = 1;
    }
};

try{
    test();
}catch(e){}
ready
Plain function loop
var test = function()
{
    for(var i = 0; i < 500; i++){
        var n = 1;
    }
};

test();
ready

Revisions

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