结论:
- localStorage的性能和JS变量的读写性能几乎一样;
- Safari的JS渲染性能要优于Chrome7~8倍;
通过localStorage读取耗时
<html>
<head>
<script type="text/javascript">
var storage=window.localStorage;
storage["user"]={name:"Li",age:27};
var d = new Date()
for (var i = 1000; i >= 0; i--) {
storage.setItem("user",i);
console.info(storage.getItem("user"))
};
console.info(new Date() -d )
</script>
</head>
<body>
</body>
</html>
结果:单位(ms)
Safari | Chrome |
---|---|
30 | 230 |
Chrome 230ms
通过变量
<html>
<head>
<script type="text/javascript">
var storage={name:"Li",age:27};
var d = new Date()
for (var i = 1000; i >= 0; i--) {
storage.name = i;
console.info(storage.name)
};
console.info(new Date() -d )
</script>
</head>
<body>
</body>
</html>
结果:单位(ms)
Safari | Chrome |
---|---|
23 | 228 |
网友评论