Reverse Array Concatenation

Benchmark created on


Description

Tests if it is faster to reverse the array and use Array.concat(), or just iterate in reverse order, using Array.push() for each.

Setup

targetArray = (function() {
      var _i, _results;
      _results = [];
      for (i = _i = 0; _i < 10; i = ++_i) {
        _results.push(i);
      }
      return _results;
    })();
    
    testArray = (function() {
      var _i, _results;
      _results = [];
      for (i = _i = 10; _i <= 15; i = ++_i) {
        _results.push(i);
      }
      return _results;
    })();

Test runner

Ready to run.

Testing in
TestOps/sec
Reverse, then concat()
targetArray.concat(testArray.reverse());
ready
push() in descending loop
for (_i = testArray.length - 1; _i >= 0; _i += -1) {
  targetArray.push(testArray[_i]);
}
ready

Revisions

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