invoke vs invoke undef

JavaScript performance comparison

Test case created

Preparation code

<script>
  Benchmark.prototype.setup = function() {
    function fn(a,b,c,d) {}
    var obj = {};
     obj.fn = fn;
    var args=['a','b','c','d'];
    var fastInvoke = function(a) {
        switch(a.length) {
          case 1:  return a[0]();
          case 2:  return a[0](a[1]);
          case 3:  return a[0](a[1], a[2]);
          case 4:  return a[0](a[1], a[2], a[3]);
          case 5:  return a[0](a[1], a[2], a[3], a[4]);
          case 6:  return a[0](a[1], a[2], a[3], a[4], a[5]);
          case 7:  return a[0](a[1], a[2], a[3], a[4], a[5], a[6]);
          case 8:  return a[0](a[1], a[2], a[3], a[4], a[5], a[6], a[7]);
          case 9:  return a[0](a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8]);
          case 10: return a[0](a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9]);
          case 11: return a[0](a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], a[10]);
          default: return a.shift().apply(null, a)
        }
    };
   
  };
</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
invoke

obj.fn('a','b','c','d');
pending…
invoke undef
fn('a','b','c','d');
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