If vs. empty function
JavaScript performance comparison
Info
What's better? To check every if a function is defined or place a empty function as default.
Preparation code
<script>
Benchmark.prototype.setup = function() {
var funcs = {
emptyFunc: new Function(),
someFunc: function() {
var x = 1;
var y = 5;
return x > y
},
nullFunc: null
}
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
empty func |
|
pending… |
if switch |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments