call vs apply (v49)

Revision 49 of this benchmark created on


Setup

function Target() {
    }
    
    function invokeTarget(args) {
      switch (args.length) {
        case 0: Target();
        case 1: Target(args[0]);
        case 2: Target(args[0], args[1]);
        case 3: Target(args[0], args[1], args[2]);
        case 4: Target(args[0], args[1], args[2], args[3]);
        case 5: Target(args[0], args[1], args[2], args[3], args[4]);
      }
    }
    
    function invokeTarget2(args) {
      if (0 === args.length) { Target(); }
      else if (1 === args.length) { Target(args[0]); }
      else if (2 === args.length) { Target(args[0], args[1]); }
      else if (3 === args.length) { Target(args[0], args[1], args[2]); }
      else if (4 === args.length) { Target(args[0], args[1], args[2], args[3]); }
      else if (5 === args.length) { Target(args[0], args[1], args[2], args[3], args[4]); }
    }

Test runner

Ready to run.

Testing in
TestOps/sec
Call
Target.call(Target);
Target.call(Target, 0);
Target.call(Target, 0, 1);
Target.call(Target, 0, 1, 2);
Target.call(Target, 0, 1, 2, 3);
Target.call(Target, 0, 1, 2, 3, 4);
 
ready
Apply
Target.apply(Target, []);
Target.apply(Target, [0]);
Target.apply(Target, [0, 1]);
Target.apply(Target, [0, 1, 2]);
Target.apply(Target, [0, 1, 2, 3]);
Target.apply(Target, [0, 1, 2, 3, 4]);
 
ready
Normal invocation
Target();
Target(0);
Target(0, 1);
Target(0, 1, 2);
Target(0, 1, 2, 3);
Target(0, 1, 2, 3, 4);
 
ready
Indirection
invokeTarget([]);
invokeTarget([0]);
invokeTarget([0, 1]);
invokeTarget([0, 1, 2]);
invokeTarget([0, 1, 2, 3]);
invokeTarget([0, 1, 2, 3, 4]);
 
ready
Indirection 2
invokeTarget2([]);
invokeTarget2([0]);
invokeTarget2([0, 1]);
invokeTarget2([0, 1, 2]);
invokeTarget2([0, 1, 2, 3]);
invokeTarget2([0, 1, 2, 3, 4]);
 
ready

Revisions

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