程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> SqlServer數據庫 >> 關於SqlServer >> 用數據對比MySql和MS Sql速度

用數據對比MySql和MS Sql速度

編輯:關於SqlServer

用以下程序測試MySQL和sqlserver的插入速度:共240000條數據:

import Java.sql.Connection;
import Java.sql.DriverManager;
import Java.sql.SQLException;
import Java.sql.Statement;
import Java.sql.ResultSet;
public class GASelectTest {


 public static final int accuracy=10;
 static Connection conn=null;
 static Statement sql=null;
 static ResultSet rs=null;
 public static int[][]class1={//服務類1的決策矩陣
     {12 ,16 ,12 ,15 ,15 ,11 ,17 ,16 ,20 ,7 },
     {6 ,21 ,3 ,16 ,22 ,9 ,9 ,20 ,22 ,4 },
     {6 ,9 ,3 ,5 ,15 ,15 ,18 ,11 ,15 ,5 },
     {6 ,21 ,16 ,4 ,16 ,19 ,11 ,17 ,19 ,5 },
     {8 ,11 ,18 ,18 ,21 ,4 ,15 ,6 ,22 ,6 }     public static int[][]class2={//服務類2的決策矩陣
     {9 ,9 ,17 ,12 ,21 ,12 ,22 ,9 ,21 ,9 ,7 ,20 ,3 ,14 ,6 ,5 ,21 ,14 ,16 ,19 },
     {3 ,21 ,9 ,4 ,3 ,8 ,5 ,6 ,4 ,7 ,8 ,11 ,18 ,8 ,15 ,19 ,17 ,4 ,3 ,7 },
     {17 ,6 ,12 ,6 ,19 ,20 ,18 ,19 ,19 ,11 ,4 ,16 ,22 ,3 ,19 ,18 ,6 ,3 ,17 ,11 },
     {8 ,15 ,12 ,7 ,5 ,7 ,17 ,16 ,19 ,5 ,18 ,16 ,4 ,8 ,13 ,8 ,17 ,3 ,14 ,21 },
     {9 ,21 ,17 ,19 ,12 ,3 ,12 ,11 ,3 ,9 ,20 ,19 ,5 ,6 ,20 ,6 ,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13 ,13 ,14 ,3 ,21 ,20 ,14 ,9 ,15 ,11 ,3 ,3 ,5 ,4 ,22 ,3 ,11 ,17 ,22 ,3 ,17 ,20 ,6 ,5 ,5 ,19 ,17 ,9 ,19 ,13 ,17 ,3 ,9 },
     {11 ,4 ,21 ,21 ,8 ,12 ,5 ,4 ,18 ,18 ,20 ,17 ,14 ,18 ,15 ,17 ,11 ,13 ,6 ,22 ,12 ,11 ,7 ,6 ,8 ,3 ,9 ,7 ,10 ,14 ,21 ,5 ,7 ,13 ,11 ,21 ,8 ,4 ,22 ,14 },
     {14 ,20 ,11 ,13 ,4 ,4 ,20 ,5 ,18 ,21 ,4 ,17 ,4 ,11 ,15 ,22 ,11 ,20 ,16 ,10 ,18 ,7 ,11 ,11 ,10 ,21 ,13 ,12 ,22 ,22 ,3 ,17 ,5 ,19 ,3 ,19 ,6 ,17 ,7 ,21 }     public static Connection getConnection(){
     try{
      //Class.forName("net.sourceforge.jtds.jdbc.Driver");
      Class.forName("com.MySQL.jdbc.Driver");
     }catch(ClassNotFoundException e){
      System.out.println("沒有找到驅動");      try{
      //conn=DriverManager.getConnection("jdbc:jtds:sqlserver://localhost:1433/AlgorithmData","sa","");
      conn=DriverManager.getConnection("jdbc:MySQL://localhost:3306/algorithmdata","root","root");
     }catch(SQLException e){
      System.out.println("連接數據庫出錯!");      return conn;     public static void insertData(String str){
     try{
      sql=conn.createStatement();
      sql.executeUpdate(str);
     }catch(SQLException e){
      System.out.println("數據插入失敗!");     }
    public static void connClose(){
     try{
      sql.close();
      conn.close();
     }catch(SQLException e){
      System.out.println("數據庫關閉失敗!");     }
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  try{
   int count=0;
   System.out.println("計算開始:");
    conn=getConnection();
   long starttime=System.currentTimeMillis();
   for(int i=0;i<class1[0].length;i++){
    for(int j=0;j<class2[0].length;j++){
     for(int k=0;k<class3[0].length;k++){
      for(int l=0;l<class4[0].length;l++){
          int responsetime1=class1[0][i]+Math.max(class2[0][j], class3[0][k])+class4[0][l];
          int price1=class1[1][i]+class2[1][j]+class3[1][k]+class4[1][l];
          int expiretime1=Math.min(Math.min(class1[2][i], class2[2][j]),  Math.min(class3[2][k], class4[2][l]));
          int availability1=class1[3][i]*Math.min(class2[3][j], class3[3][k])*class4[3][l];
          int securitylevel1=Math.min(Math.min(class1[4][i], class2[4][j]),  Math.min(class3[4][k], class4[4][l]));;
          double sum1=Math.exp(-accuracy*responsetime1)+Math.exp(-accuracy*price1)+Math.exp(-accuracy*expiretime1)+Math.exp(-accuracy*availability1)+Math.exp(-accuracy*securitylevel1);
          double result=-Math.log(sum1)/accuracy;
          count++;
          System.out.print(count+"\t");
          if(count%100==0){
           System.out.println();           //String str="insert list(class1,class2,class3,class4,result)values('"+i+"','"+j+"','"+k+"','"+l+"','"+result+"')";
          String str="insert garesult(class1,class2,class3,class4,result)values("+i+","+j+","+k+","+l+","+result+")";
          insertData(str);
          sql.close();                      conn.close();
   long endtime=System.currentTimeMillis();
   System.out.println("耗時:"+(endtime-starttime));
  }catch(SQLException e){
   System.out.println("關閉錯誤!");   

耗時:SqlServer:3分鐘

       MySQL:65分鐘,速度對比,一目了然!

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved