I did some benchmarking on my setup (i7 @ 3.07GHz, 6GB ram) with the Object.keys method and noticed some interesting results.
This is the code I tried:
var foo = {};
for (var i = 0; i < 600000; i++) {
foo[i] = true;
}
console.time("foobar");
var keys = Object.keys(foo);
console.timeEnd("foobar");
I replaced xxx with different values, starting at 10 000 and going up to 1 000 000. When I came to 400k execution-time was around 121ms, 500k ~130ms. But then at 600k it jumped to 250ms. Why does it do this?