3 ms·
I am just not quite buying the fact that indexing a 1d array will be slower than indexing an array of arrays As it happens, I recently ran similar benchmarks (
by gruseom 16y ago
I am just not quite buying the fact that indexing a 1d array will be slower than indexing an array of arrays
As it happens, I recently ran similar benchmarks (on sparse arrays represented using JS hashes) and got similar results: a hash of hashes performed much faster than a single hash with computed keys, even though the keys seemed trivial to compute. It was a disappointing outcome insofar as the data structure in question is performance-critical and I had hoped that flattening it would be an optimization. Another almost clever idea backfires. I wonder whether collision/balancing issues in the underlying hashtable implementation are responsible.
Admittedly, our sparse grid is a different beast than the OP's dense grid, except that these things are not so different in Javascript, whose arrays are weird specialized hashes anyway, and thus not so different when dense vs. sparse. (Though not the same, either: http://news.ycombinator.com/item?id=1999637 http://news.ycombinator.com/item?id=1999637)