arguments-as-array

JavaScript performance comparison

Test case created by WebReflection

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  const {push, slice} = [];
  const {from} = Array;
  
  const asESNext = (...args) => args;
  
  function viaForLoop() {
    const arr = [];
    for (let i = 0, {length} = arguments; i < length; i++)
      arr[i] = arguments[i];
    return arr;
  }
  
  function viaPush() {
    const arr = [];
    push.apply(arr, arguments);
    return arr;
  }
  
  function viaSlice() {
    return slice.call(arguments);
  }
  
  function viaArrayFrom() {
    return from(arguments);
  }
  
  function viaBabelTransform() {
    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }
    return args;
  }
  
  var 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
asESNext
result = asESNext({}, 123, [4, 5, 6], '789');
pending…
viaForLoop
result = viaForLoop({}, 123, [4, 5, 6], '789');
pending…
viaPush
result = viaPush({}, 123, [4, 5, 6], '789');
pending…
viaSlice
result = viaSlice({}, 123, [4, 5, 6], '789');
pending…
viaArrayFrom
result = viaArrayFrom({}, 123, [4, 5, 6], '789');
pending…
viaBabelTransform
result = viaBabelTransform({}, 123, [4, 5, 6], '789');
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