compare array unique algorithms (v15)

Revision 15 of this benchmark created on


Preparation HTML

<script>
var utils = {
uniq: function(arr) {
    var temp = {}, l = arr.length, result = [];
    while(l) !temp[arr[--l].id] && result.unshift(arr[l]) && (temp[arr[l].id] = 1);
    return result;
  },

  uniqDouble: function(arr) {
    var temp = {}, l = arr.length, result = [];
    while(l) temp[arr[--l].id] = arr[l];
    for (var k in temp) result.push(temp[k]);
    return result;
  }
}
</script>

Setup

var array = [ 
      { id: 1 },
      { id: 2 },
      { id: 3 },
      { id: 4 },
      { id: 5 },
      { id: 6 },
      { id: 7 },
      { id: 8 },
      { id: 9 },
      { id: 9 },
      { id: 10 },
      { id: 1, new: true },
      { id: 2, new: true },
      { id: 3, new: true }
    ]

Test runner

Ready to run.

Testing in
TestOps/sec
single loop
utils.uniq(array);
ready
double loop
utils.uniqDouble(array);
ready

Revisions

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