Array.indexOf vs Object's "in operator

JavaScript performance comparison

Test case created

Info

Testing if access through Array.indexOf or Object's in Operator is faster.

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var arr = [
       'that',
       'is',
       'some',
       'nice',
       'some',
       'test',
       'here',
    ]
   
    var obj = {
       'that' : null,
       'is' : null,
       'some' : null,
       'nice' : null,
       'test' : null,
       'here' : null
    }
};
</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 - Find first element
arr.indexOf('that');
pending…
Object - Find first element
'that' in obj;
pending…
Array - Find last element
arr.indexOf('here');
pending…
Object - Find last element
'here' in obj;
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