throw error vs string perf

JavaScript performance comparison

Revision 3 of this test case created

Preparation code

<script>

function MyCustomError(message) {
    this.message = message;
    this.name = "MyCustomError";
    //Error.captureStackTrace(this, MyCustomError);
}
MyCustomError.prototype = Object.create(Error.prototype);
MyCustomError.prototype.constructor = MyCustomError;
function throwError(){
    throw new Error("I'm an error");
}
function throwString(){
    throw "I'm an error";
}

function throwNoCollect() {
    throw new MyCustomError("I'm an error");
}

function dontThrow() {
    return undefined;
}
</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
error
try{
throwError();
}catch(e){};
pending…
string
try{
throwString();
}catch(e){};
pending…
no collection
try{
throwNoCollect();
}catch(e){};
pending…
don't throw
try{
dontThrow();
}catch(e){};
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment