Synchronous Error Passing vs Throwing
JavaScript performance comparison
Info
Here we will test to see if passing values and including the error is faster than throwing an error if one were to happen. In all these tests, an error will not be thrown/passed - to see real-world speeds.
Preparation code
<script>
Benchmark.prototype.setup = function() {
var console = console ? console : { "log": function() {} };
function recurse(loops) {
if (loops >= 0) {
recurse(--loops);
} else {
return 0;
}
}
function cjsCallback(loops, callback) {
if (loops >= 0) {
cjsCallback(--loops, callback);
} else {
callback.call(null, 0);
}
}
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Try/Catch Recurse |
|
pending… |
Instanceof/Return Recurse |
|
pending… |
CJS Callback Recurse |
|
pending… |
Try/Catch Anonymous |
|
pending… |
Instanceof/Return Anonymous |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments