If vs. empty function

JavaScript performance comparison

Test case created by Florian Maertl

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.

Testing in unknown unknown
Test Ops/sec
empty func
funcs.emptyFunc();
pending…
if switch
if (funcs.emptyFunc != null) {
  funcs.emptyFunc();
}
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