• 用一段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>
    

      

  • 相关阅读:
    暑假学习
    暑假学习
    暑假学习
    暑假学习
    暑假学习
    经验教训+总结
    NT 时刻
    联赛模拟测试 17
    联赛模拟测试 16
    联赛模拟测试 15
  • 原文地址:https://www.cnblogs.com/zhu-xingyu/p/5222085.html
Copyright © 2020-2023  润新知