_.without vs Array.prototype.remove
JavaScript performance comparison
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 (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);
}
};
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
_.without |
|
pending… |
Array.prototype.remove |
|
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:
- Revision 1: published
- Revision 2: published
0 comments