Javascript string array combine concat, push, spread

JavaScript performance comparison

Revision 281 of this test case created by Marcel Lucas

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  let arr1 = [];
  let arr2 = [];
  
  function randomString(){
   return Date.now().toString(36)+''+Math.random().toString(36)
  }
  
  for (let i = 0; i < 1000; i++) {
    arr1.push(randomString());
    arr2.push(randomString());
  }
  

};
</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
concat es6
var arr = [...arr1, ...arr2]
pending…
push
var arr = [];
Array.prototype.push.apply(arr, arr1);
Array.prototype.push.apply(arr, arr2);
pending…
concat
var arr = [].concat(arr1, arr2);
pending…
push es6
var arr = [].push(...arr1, ...arr2);
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