性能分析

今天在我的笔记本电脑上进行写入分析,共插入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='\n';
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以下。当然不可能达到这么高的值!

 

posted on 2016-01-16 16:40  小跳coder  阅读(128)  评论(0编辑  收藏  举报

导航