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
  • 相关阅读:
    高斯消元
    UVa12103
    UVa10294
    UVa11762
    牛客网算法工程师能力评估
    华为研发工程师编程题
    网易2017春招笔试真题编程题集合
    2017网易有道内推编程题
    2017网易雷火实习生招聘编程题
    数组---面试知识点整理
  • 原文地址:https://www.cnblogs.com/xiaotiao-coder/p/5135758.html
Copyright © 2011-2022 走看看