arguments transform vs direct

JavaScript performance comparison

Test case created by tenbits

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  function indexOf(items, fn /**, other optional args */){
  for (var i = 0; i < items.length; i++) {
                  if (fn(items[i]) == true) return i;
              }
              return -1;
  }
  window.items = [1,2,3,4,5];
  function callArgs(){
    var args = Array.prototype.slice.call(arguments);
    args.unshift(window.items);
    var result = indexOf.apply(this, args);
    return result;
  }
  
  function callDirect(){
     var result = indexOf(window.items, arguments[0], arguments[1], arguments[2], arguments[3]);
     return result;
  }
  function callDirectCheckLength(){
     var length = arguments.length;
     var result = indexOf(window.items, length > 0 ? arguments[0] : null, length > 1 ? arguments[1] : null, length > 2 ?arguments[2] : null, length > 3 ? arguments[3] : null);
     return result;
  }

};
</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
args
callArgs(function(x){ return x > 10; });
pending…
direct
callDirect(function(x){ return x > 10; });
pending…
directCheck
callDirectCheckLength(function(x){ return x > 10; });
pending…
direct without OutOfRange
callDirect(function(x){ return x > 10; },1,2,3);
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