filter versus dictionary (v7)

Revision 7 of this benchmark created on


Setup

var array = [{
      "name": "Joe",
      "age": 17
    }, {
      "name": "Bob",
      "age": 17
    }, {
      "name": "Carl",
      "age": 35
    }];

Test runner

Ready to run.

Testing in
TestOps/sec
map
var lookup = {};
var items = array;
var result = [];

for (var item, i = 0; item = items[i++];) {
  var name = item.age;

  if (!(name in lookup)) {
    lookup[name] = 1;
    result.push(name);
  }
}
ready
dictionary
var unique = {};
var distinct = [];
for (var i in array) {
  if (typeof(unique[array[i].age]) == "undefined") {
    distinct.push(array[i].age);
  }
  unique[array[i].age] = 0;
}
ready

Revisions

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