bind vs closure vs applied vs called vs protod

JavaScript performance comparison

Revision 23 of this test case created by dan

Preparation code

<script>
function add( num ) {
  this.age.val += num; }

function get_protod( func, self ) {
  var n = Object.create(self);
  n.func = func;
  return function(arg){
    n.func(arg); } }

function get_closured( func, self ) {
  return function( arg ) { 
    self.func = func;
    self.func( arg );
    delete self.func; } }

function get_applied( func, self ) { 
  return function() {
    func.apply( self, arguments ); } }

function get_called( func, self ) {
  return function( arg ) {
    func.call( self, arg ); } }

function get_bound( func, self ) {
  return func.bind( self ); }
</script>
      
<script>
Benchmark.prototype.setup = function() {
  obj = { age: { val: 0 } };
  
  closured = get_closured( add, obj );
  bound = get_bound( add, obj );
  called = get_called( add, obj );
  applied = get_applied( add, obj );
  protod = get_protod( add, obj );

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Closured
closured( 10 );
pending…
Bound
bound( 10 );
pending…
Called
called( 10 );
pending…
Applied
applied( 10 );
pending…
Protod
protod( 10 );
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.

0 Comments