用一段JS代码来比较各浏览器的极限内存与运算速度

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
     <script>
   
     var initTime=new Date();  //程序执行初始时间

     var odd=0;      //计数器
       //生成不同的对象
       function  produceOb(i){
            var n=0;
            var temp='';
            var str={} //空对象
            while(n<i){
                temp="a"+temp;
                n++;
            }
            str.content=i+temp;  //添加对象属性,并赋不同值
            return str;

       }

       //生成20000个不同的对象插入数组,这里20000可调,你可以估计浏览器的极限值来测
       var obItems=[];
       while(odd<20000){
                obItems.push(produceOb(odd));
                odd++;
       }
      

       var terminalTime=new Date();   //插入数据结束时间
       
       //得到执行用于的时间方法
       function processTime(time1,time2){
             if( (time2.getMinutes()-time1.getMinutes())>0){
                       return (time2.getMinutes()-time1.getMinutes())*60+(time2.getSeconds()-time1.getSeconds())+"s";
             }else{
                       return (time2.getSeconds()-time1.getSeconds())+"s";
             }
       }
        console.log(obItems);  //插入后的数组

        console.log( processTime(initTime,terminalTime));   //执行时间
    

     </script>
    
</body>
</html>

  

原文地址:https://www.cnblogs.com/zhu-xingyu/p/5222085.html