Maps vs Arrays

JavaScript performance comparison

Test case created by Renan

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
Maps
var map = {
  "1": true,
  "2": true,
  "3": true,
  "4": true,
  "5": true,
  "6": true,
  "7": true,
  "8": true,
  "9": true,
  "10": true
};

for (var i = 0; i < 10000; i++) {
  var rand = Math.floor((Math.random() * 10) + 1);
  var match = !! map[rand];
}
pending…
Arrays
var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

for (var i = 0; i < 10000; i++) {
  var rand = Math.floor((Math.random() * 10) + 1);
  var match = arr.indexOf(rand) !== -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