问题描述
使用Javascript在localStorage中查找值的速度有多快?
How fast is looking up a value in localStorage with Javascript?
是否有人链接到任何性能测试,这些性能测试指示是否值得在JavaScript对象中缓存数据?还是浏览器已经缓存了从localStorage访问的值?
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?
我对localStorage的Firefox和Chrome实现特别感兴趣.
I am particularly interested in Firefox and Chrome implementations of localStorage.
推荐答案
对于它的价值,这是一个 jsperf测试.
For what it's worth, here is a jsperf test.
在FF7和IE9中,localStorage
的基准用法明显比访问常规对象属性要慢得多.当然,这只是一个微基准,不一定反映真实的使用情况或性能 ...
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...
从FF 7运行中提取的样本以操作/秒"的形式显示明显较慢"的含义:
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
此外,对可在localStorage中放置的内容有限制. YMMV.
这篇关于localStorage的速度/成本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!