Splice vs Slice

JavaScript performance comparison

Test case created by taguenizy

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  const arraySize = 1000000
  const testIndex = [
    0,
    arraySize/2,
    arraySize-1
  ]
  
  const runTest = (method) => {
    const dataSet = [
      new Array(arraySize),
      new Array(arraySize).fill(1),
      new Array(arraySize).fill('str'),
      new Array(arraySize).fill({ performance: true })
    ]
    dataSet.forEach(arr => {
      testIndex.forEach(index => 
        arr[method](index)
      );
    })
  }

};
</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
runTest('slice')
pending…
Splice
runTest('splice')
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