Remove Duplicate Array Tests

JavaScript performance comparison

Test case created by Levi Tomes

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js">
</script>

      
<script>
Benchmark.prototype.setup = function() {
  var array = {
      "sample": {
          "0": "sample1",
          "1": "sample1",
          "2": "sample1",
          "3": "sample2",
          "4": "sample2",
          "5": "sample2",
          "6": "sample2"
      },
      "sample1": {
          "0": "sample1",
          "1": "sample1",
          "2": "sample1",
          "3": "sample2",
          "4": "sample2",
          "5": "sample2",
          "6": "sample2"
      },
      "sample2": {
          "0": "sample1",
          "1": "sample1",
          "2": "sample1",
          "3": "sample2",
          "4": "sample2",
          "5": "sample2",
          "6": "sample2"
      }
  }
  

};
</script>

Preparation code output

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Using each method
  var temp = [];
  $.each(array, function(i, el) {
    if ($.inArray(el, temp) === -1) temp.push(el);
  });
  return temp;
pending…
Using for method #1
temp = {};
for (var i = 0; i < array.length; i++) {
temp[a[i]] = array[i];
}
c = [];
for (var key in temp) {
    c.push(key);
}
return c;
pending…
Using for method #2
  var temp = {};
  for (var i = 0; i < array.length; i++)
  temp[array[i]] = true;
  var r = [];
  for (var k in temp)
  r.push(k);
  return r;
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.

0 Comments