zoukankan      html  css  js  c++  java
  • 性能分析

    今天在我的笔记本电脑上进行写入分析,共插入10 000 000 个数据,每个数据占7位,耗时131秒;

    文件大小约为66.7MB

    以下是我的电脑配置:

    硬盘写入速度为5400转

     1 public class Test1 {
     2 
     3     public static void main(String[] args) throws IOException {
     4         File file=new File("d:\1.txt");
     5         FileOutputStream fos=new FileOutputStream(file);
     6         byte[] buf=null;
     7         long start=System.currentTimeMillis();
     8         for(int i=1;i<10000000;i++){ 
     9             String s=getNumber(i);
    10             buf=s.getBytes();
    11             fos.write(buf, 0, buf.length);
    12             char c='
    ';
    13             fos.write(c);
    14             System.out.println("正在写入  "+new String(buf));
    15         }
    16         long end=System.currentTimeMillis();
    17         System.out.println("写入完成! 耗时 "+(end-start)/1000+" 秒");
    18         
    19     }
    20     
    21     public static String getNumber(int i){
    22         String number="";
    23         int wei=0;
    24         int temp=i;
    25         while(i!=0){
    26             i/=10;
    27             wei++;
    28         }
    29         for(int j=0;j<7-wei;j++){
    30             number+=0;
    31         }
    32         number+=temp;
    33         return number;
    34     }
    35 }

    如果省去循环能节约多少呢?测试了一下 123秒!节约8秒!每秒插入数据81300,以此可以估计出数据库中不管是关系型数据库或者nosql数据库的性能

    瓶颈在81300以下。当然不可能达到这么高的值!

    ZZH
  • 相关阅读:
    1.5环境变量与文件查找(学习过程)
    1.4程序的机器级表示(学习过程)
    1.3信息的表示和处理(学习过程)
    hdu4706
    【多重背包】Transport Ship
    【动态规划】Mathematical Curse
    【动态规划】subsequence 1
    学习线性基
    学习秦九韶算法
    学习裴蜀定理
  • 原文地址:https://www.cnblogs.com/xiaotiao-coder/p/5135758.html
Copyright © 2011-2022 走看看