Skip to content

Instantly share code, notes, and snippets.

@bga
Created September 14, 2010 22:35
Show Gist options
  • Save bga/579905 to your computer and use it in GitHub Desktop.
Save bga/579905 to your computer and use it in GitHub Desktop.
/*
Traditionally in js we separate arrays and hashes(maps, Object, dictionary, ...)
Test shows that modern engines havent array optimization - it just hash with automatic <.length> property and sugar array like methods :(
*/
var m = 1000;
var _fill = function(a)
{
var i = a.length; while(i--)
a[i] = 0;
};
var filledArray = new Array(m)
var filledHash = {length: m};
_fill(filledArray);
_fill(filledHash);
var _traverse = function(n, a)
{
var i = n; while(i--)
{
var j = a.length; while(j--)
{
a[j] |= a[j];
}
}
};
_speedTest(
[
function(n)
{
_traverse(n, filledArray);
},
function(n)
{
_traverse(n, filledHash);
}
],
10000
);
/*
ie7 10000/10
0: 2373 ms
1: 2314 ms
chrome7
0: 855 ms
1: 818 ms
opera10.62
0: 739 ms
1: 733 ms
ff3.6 1000/5
0: 1468 ms
1: 1501 ms
ff4b3 1000/5
0: 1215 ms
1: 1183 ms
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment