slice vs spread to copy (v3)

Revision 3 of this benchmark created on


Setup

var arr = [];
    for (var i = 0; i < 100_000; i++) {
     arr.push(i);
    };
    var half = Math.floor(arr.length / 2);
      
    function randomInt(max) {
     return Math.floor(Math.random() * (max + 1));
    };

Test runner

Ready to run.

Testing in
TestOps/sec
slice
const slice = arr.slice()
ready
spread
const spread = [...arr]
ready

Revisions

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