How fast is looking up a value in localStorage with Javascript?
Does anyone have links to any performance tests that indicate whether or not it is worth caching the data in a JavaScript object? Or does the browser already cache values that are accessed from localStorage anyway?
I am particularly interested in Firefox and Chrome implementations of localStorage.
For what it's worth, here is a jsperf test.
The benchmark usage of localStorage
is significantly slower than access of a regular object properties in both FF7 and IE9. Of course, this is just a micro-benchmark, and does not necessarily reflect real-world usage or performance...
Sample pulled from my FF 7 run to show what "significantly slower" means, in ops/second:
native local-storage notes small set 374,397 13,657 10 distinct items large set 2,256 68 100 distinct items read-bias 10,266 342 1 write, 10 reads, 10 distinct items
Also, there are restrictions on what can be put in localStorage. YMMV.