Array clone

JavaScript performance comparison

Test case created by crshumate

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  let arr=[];
  for(var i=0; i<5000; i++){
     arr.push(i+1);
  }
  //let arr=[1,2,3,4,5,6,7,8,9,10];

};
</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
slice
let nArr = arr.slice();
pending…
map
let nArr = arr.map(item=>item);
pending…
spread
let nArr = [...arr];
pending…
JSON.stringify
let nArr = JSON.parse(JSON.stringify(arr));
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