To uniquely identify each item, I need to store data using 3 keys. In this example, I am using i, j, z as the keys.
console.time('global1');
var global1 = {};
for (var i = 0; i < 100; ++i) {
for (var j = 0; j < 100; ++j) {
for (var z = 0; z < 100; ++z) {
global1[i] = global1[i] || {};
global1[i][j] = global1[i][j] || {};
global1[i][j][z] = global1[i][j][z] = { a: 123456789 };
}
}
}
console.timeEnd('global1');
console.time('global2');
var global2 = {};
for (var i = 0; i < 100; ++i) {
for (var j = 0; j < 100; ++j) {
for (var z = 0; z < 100; ++z) {
global2[[i,j,z]] = { a: 123456789 };
}
}
}
console.timeEnd('global2');
- What kind of optimization is Chrome using to make the first example significantly faster?
- What is the most efficient way to store a large amount (or more) of data?