hashtablevsarraylookup

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var hash = {
      'aaa': null,
      'bbb': null,
      'ccc': null,
      'ddd': null,
      'eee': null,
      'fff': null,
      'ggg': null,
      'hhh': null,
      'iii': null,
      'jjj': null,
      'kkk': null
    };
   
    var arr = ['aaa', 'bbb', 'ccc', 'ddd', 'eee', 'fff', 'ggg', 'hhh', 'iii', 'jjj', 'kkk'];
   
    var x;
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
arr first
for (var i = 0, len = arr.length; i < len; i++) {
  if ("aaa" === arr[i]) {
    x = true;
    break;
  }
}
x = x || false;
pending…
arr middle
for (var i = 0, len = arr.length; i < len; i++) {
  if ("fff" === arr[i]) {
    x = true;
    break;
  }
}
x = x || false;
pending…
arr last
for (var i = 0, len = arr.length; i < len; i++) {
  if ("kkk" === arr[i]) {
    x = true;
    break;
  }
}
x = x || false;
pending…
hash first
x = "aaa" in hash;
pending…
hash middle
x = "fff" in hash;
pending…
hash last
x = "kkk" in hash;
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. Here’s a list of current revisions for this page:

0 comments

Add a comment