日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql 测试与mongodb 测试对比

發布時間:2023/12/18 数据库 17 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql 测试与mongodb 测试对比 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

網上有很多相關測試對比,但是與實際項目中性能相差很多,所以還是自己測試對比了一下.mongodb甩mysql很遠啊.

mysql只有在批量操作下性能才接近mongodb,這樣mysql就必須加個緩存服務器來配合使用了,但是在實際項目中要維護緩存服務器的話也是比較繁雜的事情.

1 // mysql_test.cpp : 定義控制臺應用程序的入口點。 2 // 3 4 #include "stdafx.h" 5 #include <boost/timer.hpp> 6 #include <boost/lexical_cast.hpp> 7 #include <string> 8 9 #include <mysql_connection.h> 10 #include <mysql_driver.h> 11 #include <cppconn/statement.h> 12 #include <cppconn/exception.h> 13 14 using namespace sql::mysql; 15 using namespace boost; 16 using namespace std; 17 18 int _tmain(int argc, _TCHAR* argv[]) 19 { 20 MySQL_Driver md; 21 boost::shared_ptr<sql::Connection> con(md.connect("127.0.0.1","root","123456")); 22 if(!con->isClosed()) 23 { 24 try 25 { 26 int tcont = 1000; 27 printf("test count: %d\n", tcont); 28 string tname = "testdb"; 29 string strq = "insert "+tname+" values("; 30 con->setAutoCommit(true); 31 //con->setAutoCommit(false); 32 boost::shared_ptr<sql::Statement> ssm(con->createStatement()); 33 ssm->execute("use test;"); 34 boost::timer tt; 35 for (int i = 0; i<tcont;i++) 36 { 37 ssm->execute(strq + lexical_cast<string>(i) + ",\"test\");"); 38 } 39 //con->commit(); 40 printf("insert time: %lf(s)\n", tt.elapsed()); 41 42 strq = "update "+tname+" set _str = \"abcd\" where _id = "; 43 tt.restart(); 44 for (int i = 0; i<tcont;i++) 45 { 46 ssm->executeUpdate(strq + lexical_cast<string>(i)+";"); 47 } 48 //con->commit(); 49 printf("update time: %lf(s)\n", tt.elapsed()); 50 51 strq = "select * from "+tname+" where _id = "; 52 tt.restart(); 53 for (int i = 0; i<tcont;i++) 54 { 55 boost::shared_ptr<sql::ResultSet> rset(ssm->executeQuery(strq + lexical_cast<string>(i)+";")); 56 } 57 58 printf("find time: %lf(s)\n", tt.elapsed()); 59 60 strq = "delete from "+tname+" where _id = "; 61 tt.restart(); 62 for (int i = 0; i<tcont;i++) 63 { 64 ssm->execute(strq + lexical_cast<string>(i)+";"); 65 } 66 //con->commit(); 67 printf("remove time: %lf(s)\n", tt.elapsed()); 68 } 69 catch(sql::SQLException& e) 70 { 71 printf("error: %s\n", e.what()); 72 } 73 con->close(); 74 } 75 76 getchar(); 77 return 0; 78 } mysql_test.cpp

mongodb_test: mongodb2.4之前是沒有批量操作的,最近的2.6新增加了批量操作Bulk,效率上應該會更快

mysql_test:

下面是使用批量操作:

轉載于:https://www.cnblogs.com/zhangchengxin/p/3644916.html

總結

以上是生活随笔為你收集整理的mysql 测试与mongodb 测试对比的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。