11-08-2022 14:59
11-08-2022 14:59
I tested the capacity of localStorage. It died after 524 keys of 10,000 chars each; ie, 5,240,000 chars (so about 10 MB assuming UTF16). That's enough for about 30 minutes of accelerometer data at 50 Hz. Presumably results would vary between companions.
function testStorage() {
const maxKey = 1000
localStorage.clear()
let key=0
let value=''
let chars = '12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'
for (let i=0; i<50; i++) value += chars
console.log(`len=${value.length} chars`);
let timer = setInterval(() => {
try {
localStorage.setItem(key, value)
} catch(e) {
console.log(`setItem error: ${e.message} ${e.name}`);
clearInterval(timer)
return
}
console.log(` set key ${key}`);
key++
if (key>=maxKey) {
clearInterval(timer)
console.log(`Done tesing; saved ${maxKey*value.length} chars`);
}
}, 1000);
}