今天在個人筆記本電腦上進行寫入分析,共插入10 000 000 個數據,每一個數據佔7位,耗時131秒;sql
文件大小約爲66.7MB數據庫
如下是個人電腦配置:nosql
硬盤寫入速度爲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如下。固然不可能達到這麼高的值!spa