mysql 测试与mongodb 测试对比
2014-04-04 12:30
337 查看
网上有很多相关测试对比,但是与实际项目中性能相差很多,所以还是自己测试对比了一下.mongodb甩mysql很远啊.
mysql只有在批量操作下性能才接近mongodb,这样mysql就必须加个缓存服务器来配合使用了,但是在实际项目中要维护缓存服务器的话也是比较繁杂的事情.
mysql_test.cpp
mongodb_test: mongodb2.4之前是没有批量操作的,最近的2.6新增加了批量操作Bulk,效率上应该会更快
mysql_test:
下面是使用批量操作:
mysql只有在批量操作下性能才接近mongodb,这样mysql就必须加个缓存服务器来配合使用了,但是在实际项目中要维护缓存服务器的话也是比较繁杂的事情.
// mysql_test.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include <boost/timer.hpp> #include <boost/lexical_cast.hpp> #include <string> #include <mysql_connection.h> #include <mysql_driver.h> #include <cppconn/statement.h> #include <cppconn/exception.h> using namespace sql::mysql; using namespace boost; using namespace std; int _tmain(int argc, _TCHAR* argv[]) { MySQL_Driver md; boost::shared_ptr<sql::Connection> con(md.connect("127.0.0.1","root","123456")); if(!con->isClosed()) { try { int tcont = 1000; printf("test count: %d\n", tcont); string tname = "testdb"; string strq = "insert "+tname+" values("; con->setAutoCommit(true); //con->setAutoCommit(false); boost::shared_ptr<sql::Statement> ssm(con->createStatement()); ssm->execute("use test;"); boost::timer tt; for (int i = 0; i<tcont;i++) { ssm->execute(strq + lexical_cast<string>(i) + ",\"test\");"); } //con->commit(); printf("insert time: %lf(s)\n", tt.elapsed()); strq = "update "+tname+" set _str = \"abcd\" where _id = "; tt.restart(); for (int i = 0; i<tcont;i++) { ssm->executeUpdate(strq + lexical_cast<string>(i)+";"); } //con->commit(); printf("update time: %lf(s)\n", tt.elapsed()); strq = "select * from "+tname+" where _id = "; tt.restart(); for (int i = 0; i<tcont;i++) { boost::shared_ptr<sql::ResultSet> rset(ssm->executeQuery(strq + lexical_cast<string>(i)+";")); } printf("find time: %lf(s)\n", tt.elapsed()); strq = "delete from "+tname+" where _id = "; tt.restart(); for (int i = 0; i<tcont;i++) { ssm->execute(strq + lexical_cast<string>(i)+";"); } //con->commit(); printf("remove time: %lf(s)\n", tt.elapsed()); } catch(sql::SQLException& e) { printf("error: %s\n", e.what()); } con->close(); } getchar(); return 0; }
mysql_test.cpp
mongodb_test: mongodb2.4之前是没有批量操作的,最近的2.6新增加了批量操作Bulk,效率上应该会更快
mysql_test:
下面是使用批量操作:
相关文章推荐
- Mysql与MongoDB对比测试
- 关于MongoDB在64位服务器上依然报 mmap failed with out of memory 错误的解决方法(附Mysql性能对比测试)
- Mysql与MongoDB对比测试
- Mysql与MongoDB对比测试
- Mysql与MongoDB对比测试
- Mysql与MongoDB对比测试
- MySQL基于MyISAM引擎和InnoDB引擎性能测试对比
- MongoDB、HandlerSocket和MySQL性能测试及其结果分析
- MySQL与MongoDB之SQL语法对比
- MySQL和MongoDB的性能测试
- mongodb与mysql的命令对比
- mysql-测试环境对比生产环境-表、存储过程
- Mysql 在windows 2000和 hp-ux上性能 对比测试
- mongodb与mysql命令对比
- MySQL和MongoDB设计实例对比
- mysql与mongodb、redis的性能对比,包含源代码
- MySQL 5.6 not in 和表关联性能测试对比
- MongoDB系列教程(五):mongo语法和mysql语法对比学习
- mongodb与mysql命令对比
- MongoDB和MySQL性能测试及其结果分析