Maps vs Arrays

JavaScript performance comparison

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

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

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