美文网首页
HTML5中 localStorage 性能分析

HTML5中 localStorage 性能分析

作者: 河的左岸 | 来源:发表于2017-06-06 21:56 被阅读0次

    结论:

    • 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
    Safari 30ms
    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

    相关文章

      网友评论

          本文标题:HTML5中 localStorage 性能分析

          本文链接:https://www.haomeiwen.com/subject/wojnfxtx.html