Maps vs Arrays

JavaScript performance comparison

Revision 2 of this test case created by

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": 1,
  "2": 2,
  "3": 3,
  "4": 4,
  "5": 5,
  "6": 6,
  "7": 7,
  "8": 8,
  "9": 9,
  "10": 10
};

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);
}
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