bind vs closure vs applied vs called vs protod (v23)

Revision 23 of this benchmark created by dan on


Preparation HTML

<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>

Setup

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 );

Test runner

Ready to run.

Testing in
TestOps/sec
Closured
closured( 10 );
ready
Bound
bound( 10 );
ready
Called
called( 10 );
ready
Applied
applied( 10 );
ready
Protod
protod( 10 );
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.