merge-array implementations

JavaScript performance comparison

Revision 26 of this test case created by Gerardo Lima

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  const arr1 = Array.from(Array(5000), (x,i) => i + 1)
  const arr2 = Array.from(Array(5000), (x,i) => i - 1)
  
  const arr1Length = arr1.length; 
  const arr2Length = arr2.length;
  
  // avoids compiling function inside the loop
  const pushApply = async (trg, off, src) => {
    for(var i = off, l = src.length; i < l; i++){
      trg[i] = src2[i];
    }
  }
  

};
</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
async
const target = [];
targetlength = arr1Length + arr2Length;

const p1 = pushApply(target, 0, arr1)
const p2 = pushApply(target, arr1Length, arr2)
Promise.all(p1, p2)
pending…
push (naive 2)
// Pre allocate size
arr1.length = arr1Length + arr2Length

// Add arr2 items to arr1
for(var i = 0; i < arr2Length; i++){
  arr1[arr1Length + i] = arr2[i]
}
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