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

Revision 3 of this benchmark created by srimathy 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
_.without(arr, i);
++i;
ready
Array.prototype.remove
arr2.remove(j);
++j;
ready

Revisions

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