Performance of methods to insert item at start of array (v2)

Revision 2 of this benchmark created on


Setup

var arr = [{id: 1234, filterName: "Filter by Author", value: "author"}, {id: 1234, filterName: "Filter by Author", value: "author"}, {id: 5678, filterName: "Filter by Book Type", value: "bookType"}];
  
  function unshift() {
    arr.unshift({
    	id: '0000', filterName: "Choose a Filter", value: ""
    });
    return arr;
  }
  
  function concat() {
    return [{id: '0000', filterName: "Choose a Filter", value: ""}
    ].concat(arr)
  }
  
    function spread() {
    return [{id: '0000', filterName: "Choose a Filter", value: ""
    }, ...arr]
  }
  
    function splice() {
    return arr.splice(0,0, {id: '0000', filterName: "Choose a Filter", value: ""
    })
  }

Test runner

Ready to run.

Testing in
TestOps/sec
Add a new option to Array of filters at position 0 with unshift
unshift()
ready
Add a new option to Array of filters at position 0 with concat
concat()
ready
Add a new option to Array of filters at position 0 with spread operator
spread()
ready
Add a new option to Array of filters at position 0 with splice
splice()
ready

Revisions

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