Dict vs Flattened lookup

JavaScript performance comparison

Test case created by Joshua Inkenbrandt

Preparation code

<script>
  var types = ['t', 'ot', 'p', 'op', 'or', 'oa'];
  var dict = {};
  var flat = [];
  
  var collectionSize = 10000;
  
  for (var i = 0; i < collectionSize; i++) {
    var t = types[Math.round(Math.random() * types.length)];
    dict[t] = dict[t] || [];
    dict[t].push(i);
    flat.push(t + i);
  }
  
  dict['t'].push(999);
  flat.push('t999');
</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
Dict lookup of track 999
dict['t'].indexOf(999) != -1
pending…
Flat lookup of track 999
flat.indexOf('t999') != -1
pending…

Compare results of other browsers

Revisions

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

0 Comments