map vs object for small enum

JavaScript performance comparison

Test case created by gartz

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  const map = new Map([
    [1, 1],
    [2, 1],
    [3, 1],
    [4, 1],
    [5, 1],
    [6, 1],
  ]);
  
  const obj = {
    [1]: 1,
    [2]: 1,
    [3]: 1,
    [4]: 1,
    [5]: 1,
    [6]: 1,
  };

};
</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
map
const a = map.has(4) ? map.get(4) : -1;
const b = map.has(10) ? map.get(10) : -1;
pending…
obj
const a = obj[4] || -1;
const b = obj[10] || -1;
pending…

Revisions

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

0 Comments