Remove Duplicate Array Tests

JavaScript performance comparison

Revision 2 of this test case created

Preparation code

<script src="//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>

Test runner

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

Java applet disabled.

Testing in unknown unknown
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…
d
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. Here’s a list of current revisions for this page:

0 comments

Add a comment