Try/Catch vs Variable

JavaScript performance comparison

Test case created by Trey Keown

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function divide (denominator) {
        return 2/denominator;
    }
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
If
for (i=0; i<50; i++) {
    if (i) divide(i);
}
pending…
Try/Catch
for (i=0; i<50; i++) {
    try {
        divide(i);
    } catch (e) {}
}
pending…
Try/Finally
for (i=0; i<50; i++) {
    try {
        divide(i);
    } finally {}
}
pending…

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

Compare results of other browsers

0 comments

Add a comment