array removal methods

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var arr, _base, _base1, _i, _results;
   
    (_base = Array.prototype).remove || (_base.remove = function(e) {
      var t, _ref;
      if ((t = this.indexOf(e)) > -1) {
        return ([].splice.apply(this, [t, t - t + 1].concat(_ref = [])), _ref);
      }
    });
   
    (_base1 = Array.prototype).fastRemove || (_base1.fastRemove = function(element) {
      var index;
      index = this.indexOf(element);
      this[index] = this[this.length - 1];
      return element;
    });
   
    arr = (function() {
      _results = [];
      for (var _i = 0; 0 <= 0xFFFF ? _i <= 0xFFFF : _i >= 0xFFFF; 0 <= 0xFFFF ? _i++ : _i--){ _results.push(_i); }
      return _results;
    }).apply(this);
};
</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
remove head
arr.remove(arr[0])
pending…
remove mid
arr.remove(arr[Math.floor(arr.length/2)])
pending…
remove tail
arr.remove(arr[arr.length-1])
pending…
fastRemove head
arr.fastRemove(arr[0])
pending…
fastRemove mid
arr.fastRemove(arr[Math.floor(arr.length/2)])
pending…
fastRemove tail
arr.fastRemove(arr[arr.length-1])
pending…

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

Compare results of other browsers

0 comments

Add a comment