slice/concat vs concat/splice

Benchmark created on


Preparation HTML

<script>
  function remove1(list, index) { var l
    l = list.slice(0, index)
    l.push.apply(l, list.slice(index + 1))
    return l
  }
  
  function remove2(list, index) {
    return list.slice(0, index).concat(list.slice(index + 1))
  }
  
  function remove3(list, index) { var l
    l = list.concat()
    l.splice(index, 1)
    return l
  }
  
  var arr = Array(100).join("0")
                      .split("0")
                      .map(function(v,k){ return k })
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
slice + push.apply
remove1(arr, 20)
ready
slice + concat
remove2(arr, 20)
ready
concat + splice
remove3(arr, 20)
ready

Revisions

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