_.without vs Array.prototype.remove

JavaScript performance comparison

Revision 2 of this test case created

Info

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

Preparation code

<script src="//underscorejs.org/underscore-min.js"></script>
<script>
Benchmark.prototype.setup = function() {
    var arr =  _.range(100000);
    var arr2 = _.range(100000);
    var i = 0;
    var j = 0;
   
    Array.prototype.remove = function(from, to) {
      var rest = this.slice((to || from) + 1 || this.length);
      this.length = from < 0 ? this.length + from : from;
      return this.push.apply(this, rest);
    };
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
_.without
_.without(arr, i);
++i;
pending…
Array.prototype.remove
arr2.remove(j);
++j;
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment