benchmark for Domenic

JavaScript performance comparison

Test case created by Andreas Göbel

Preparation code

<script>
  Array.prototype.remove = function(elem) {
   var match = -1;
 
   while ((match = this.indexOf(elem)) > -1) {
    this.splice(match, 1);
   }
  };
 
  Array.prototype.remove2 = function(value) {
   for (var i = 0; i < this.length;) {
    if (this[i] === value) {
     this.splice(i, 1);
    }
    else {
     ++i;
    }
   }
  }
 
  Array.prototype.remove3 = function(elem) {
   var len = this.length;
 
   while (len--) {
    if (this[len] === elem) this.splice(len, 1);
   }
  };
 
  var testArray = [9, 8, 7, 6, 5, 4, 3, 2, 1];
</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
indexOf
testArray.remove(5);
pending…
single pass
testArray.remove2(5);
pending…
while
testArray.remove3(5);
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