JavaScript Dictionary vs Array iteration speed

JavaScript performance comparison

Test case created by Bunzaga

Info

I just wanted to see which was faster to iterate through a collection of unsorted, un-ordered elements.

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var map = {0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,10:10,11:11,12:12,13:13,14:14,15:15,16:16,17:17,18:18,19:19};
    var arr = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19];
};
</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
Dictionary
for(var i in map){
}
pending…
Array
for(var i = 0, iMax = arr.length; i < iMax; i++){
}
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