_.without vs Array.prototype.remove (v4)

Revision 4 of this benchmark created on


Description

Who's faster to delete an element from an array, underscore's without method or implementation of Array remove method ?

Preparation HTML

<script src="//underscorejs.org/underscore-min.js"></script>

Setup

var arr = _.range(10000);
    var arr2 = _.range(10000);
    var i = 0;
    var j = 0;
    
    Array.prototype.remove = function(needle) {
      var i = 0;
      while (this[i] !== needle && i < this.length - 1)++i;
      if (this[i] === needle) {
        this.splice(i, 1);
      } else {
        throw new Error(needle + " not found in array " + this);
      }
    };

Test runner

Ready to run.

Testing in
TestOps/sec
_.without
// async test
_.without(arr, i);
++i;
ready
Array.prototype.remove
// async test
arr2.splice(j)
ready

Revisions

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