z-950 / blog

This is a blog for myself
0 stars 0 forks source link

性能相关 #7

Open z-950 opened 3 years ago

z-950 commented 3 years ago

环境:Windows 10 64bit,16G

浏览器单个tag最大内存占用

结果

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    div {
      height: 30vh;
    }
  </style>
</head>

<body>
  <div>div1</div>
  <div>div2</div>
  <div>div3</div>
  <div>div4</div>
  <div>div5</div>
  <div>div6</div>
  <div>div7</div>
  <div>div8</div>
  <div>div9</div>
  <div>div10</div>
  <script>
    const arr = []
    const n = 1 * 1000 * 1000
    let count = 0

    function increace() {
      setTimeout(() => {
        arr.push(new Array(n).fill("x"))

        count += n

        increace()
      }, 100);
    }

    window.onload = () => {
      debugger
      increace()
    }
  </script>
</body>

</html>

统计方式

其他参考资料

  1. https://js9.si.edu/js9/help/memory.html
  2. https://stackoverflow.com/questions/2936782/javascript-memory-limit
  3. https://stackoverflow.com/questions/6044147/ios-memory-allocation-how-much-memory-can-be-used-in-an-application

总结

  1. Chrome可以用window.performance.memory.jsHeapSizeLimit查看最大内存
  2. 如果考虑IOS,则假定最大内存为500MB比较合适