filter vs dictionary more data

JavaScript performance comparison

Test case created by travisjj

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  const array = [];
  for(let i = 0; i < 1000; i++){
   array.push({
    name: "Mr. " + i,
    age: i % 100
   })
  }

};

Benchmark.prototype.teardown = function() {
  array.length = 0;

};
</script>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
dictionary
var unique = [];
var distinct = [];
for( let i = 0; i < array.length; i++ ){
  if( !unique[array[i].age]){
    distinct.push(array[i].age);
    unique[array[i].age] = 1;
  }
}
pending…
map
var ages = array.map(function(obj) { return obj.age; });
ages = ages.filter(function(v,i) { return ages.indexOf(v) == i; });
pending…

Revisions

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

0 Comments