filter versus dictionary (v5)

Revision 5 of this benchmark created on


Preparation HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min.js"></script>

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 ages = array.map(function(obj) { return obj.age; });
ages = ages.filter(function(v,i) { return ages.indexOf(v) == i; });
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
underscore
var unique = _.uniq(array);
 
ready

Revisions

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