fn() vs fn.call

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var identity = function(d) { return d; };
   
    var f1 = function(d, f) {
      return f(d) || identity(d);
    };
   
    var f2 = function(d, f) {
      if (f) return f(d);
      return d;
    };
};
</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
f1
var one = f1(1);
var two = f1(1, identity);
pending…
f2
var one = f2(1);
var two = f2(1, identity);
pending…
f2
var one = f2(1);
var two = f2(1, identity);
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