Remove Duplicate Array Tests

Benchmark created by Levi Tomes on


Preparation HTML

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

Setup

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"
        }
    }

Test runner

Ready to run.

Testing in
TestOps/sec
Using each method
  var temp = [];
  $.each(array, function(i, el) {
    if ($.inArray(el, temp) === -1) temp.push(el);
  });
  return temp;
ready
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;
ready
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;
ready

Revisions

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