Use array vs arguments in function

JavaScript performance comparison

Test case created by SuperSkunk

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function log(key, keybis) {
   
    };
    function publishWithArray(keys) {
      var i, len, key;
      for (i = 0, len = keys.length; i < len; i++) {
        key = keys[i];
        log(key, key + 'test');
      }
    };
    function publishWithArguments() {
      var i, len, key;
      for (i = 0, len = arguments.length; i < len; i++) {
        key = arguments[i];
        log(key, key + 'test');
      }
    };  
   
    var array1 = ['one', 'two', 'three', 'four', 'five'];
    var array2 = ['two', 'three', 'four', 'five'];
    var array3 = ['three', 'four', 'five'];
    var array4 = ['four', 'five'];
    var array5 = ['five'];
   
};
</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
Publish with array
publishWithArray(['one', 'two', 'three', 'four', 'five']);
publishWithArray(['two', 'three', 'four', 'five']);
publishWithArray(['three', 'four', 'five']);
publishWithArray(['four', 'five']);
publishWithArray(['five']);
pending…
Publish with arguments
publishWithArguments('one', 'two', 'three', 'four', 'five');
publishWithArguments('two', 'three', 'four', 'five');
publishWithArguments('three', 'four', 'five');
publishWithArguments('four', 'five');
publishWithArguments('five');
pending…
Publish with arguments and cache array
publishWithArguments.apply(this, array1);
publishWithArguments.apply(this, array2);
publishWithArguments.apply(this, array3);
publishWithArguments.apply(this, array4);
publishWithArguments.apply(this, array5);
pending…
Publish with array and cache array
publishWithArray(array1);
publishWithArray(array2);
publishWithArray(array3);
publishWithArray(array4);
publishWithArray(array5);
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