Array vs. Object Member Lookup

JavaScript performance comparison

Test case created by thezilch

Preparation code

<script>
  var arr = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"];
  var obj = {"zero":1, "one":1, "two":1, "three":1, "four":1, "five":1, "six":1, "seven":1, "eight":1, "nine":1, "ten":1};
  var me = "six";
</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
Array Member Lookup
arr.indexOf(me) >= 0 // doesn't work in ie6 -- requires prototyping a lookup function
pending…
Object Member Lookup (in clause)
me in obj
pending…
Object Member Lookup (property lookup w/ bool casting)
!!obj[me]
 
pending…
Object Member Lookup (property lookup w/o bool casting)
obj[me]
pending…

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

Compare results of other browsers

0 comments

Add a comment