custom bind

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var Foo = function(a) {
      return this.v + a
    };
    var FooProps = function(v) {
      this.v = v;
    }
    var PublicFooCustom = function(v) {
      var private = new FooProps(v);
      return function() {
        Foo.apply(private, arguments);
      };
    }
    var PublicFooBound = function(v) {
      var private = new FooProps(v);
      return Foo.bind(private);
    }
   
    var Goo = function(v) {
      this.v = v;
    }
    Goo.prototype._ = function(a) {
      return this.v + a;
    }
   
    custom = [];
    for (var i = 0; i < 1e4; i++)
      custom.push(PublicFooCustom(i));
   
    bound = []
    for (var i = 0; i < 1e4; i++)
      bound.push(PublicFooBound(i));
   
    newed = []
    for (var i = 0; i < 1e4; i++)
      newed.push(new Goo(i));
};
</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
bind
for (var i = 0, t = 0; i < 1e4; i++)
  t += bound[i](i);
pending…
Custom
for (var i = 0, t = 0; i < 1e4; i++)
  t += custom[i](i);
pending…
New
for (var i = 0, t = 0; i < 1e4; i++)
  t += newed[i]._(i);
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