Bind, Call, Apply, Arrow, Direct, Anonymous

JavaScript performance comparison

Test case created by Luis Cruz

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  obj = {
    execute: function(cb){
      cb()
    },
  
    test: function(value){
      var a = value
    },
  
    invoke: function(value) {
      return obj.test(value)
    }
  }

};
</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
anonymous
(function() {
  obj.test(1)
})()
pending…
anonymous 2
obj.execute(function(){
  obj.test(1)
})
pending…
bind
obj.test.bind(obj, 1)()
pending…
apply
obj.test.apply(obj, [1])
pending…
call
obj.test.call(obj, 1)
pending…
arrow
() => obj.test(1)()
pending…
invoke
obj.invoke(1)
pending…
by string
obj['test'](1)
pending…
direct
obj.test(1)
pending…

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

0 Comments