rest-arguments-slice

JavaScript performance comparison

Test case created by boycgit

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  function leakyArguments () {
    return other(arguments)
  }
  
  function fromArguments () {
    var array = Array.from(arguments);
    return other(array);
  }
  
  function copyArgs () {
    var array = new Array(arguments.length)
  
    for (var i = 0; i < array.length; i++) {
      array[i] = arguments[i]
    }
  
    return other(array)
  }
  
  function sliceArguments () {
    var array = Array.prototype.slice.apply(arguments)
    return other(array)
  }
  
  function spreadOp() {
    var args = [...arguments];
    return other(args)
  }
  
  function restOp(...args) {
    return other(args)
  }
  
  function other (toSum) {
    var total = 0
    for (var i = 0; i < toSum.length; i++) {
      total += toSum[i]
    }
    return total
  }

};
</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
leakyArguments
leakyArguments(1, 2, 3);
pending…
sliceArguments
sliceArguments(1, 2, 3)
pending…
copyArgs
copyArgs(1, 2, 3)
pending…
spreadOp
spreadOp(1, 2, 3)
pending…
fromArguments
fromArguments(1,2,3)
pending…
restOp
restOp(1,2,3)
pending…

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

0 Comments