Mysql5 与 Mongodb2.4 简单性能对比
来源:互联网 发布:linux exit是什么意思 编辑:程序博客网 时间:2024/05/01 13:01
测试环境:
可惜的是硬盘是5400;
Mongodb启动
Mysql启动
测试代码:
public static void mysql() {try {Class.forName("com.mysql.jdbc.Driver");Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/sants", "sants", "123456");String sql = "insert into demo(name,birth) values(?,?)";conn.setAutoCommit(false);long start = System.currentTimeMillis();PreparedStatement pst = conn.prepareStatement(sql);for (int n = 0; n < max; n++) {pst.setString(1, "Name" + Math.random());pst.setDate(2, new java.sql.Date(System.currentTimeMillis()));pst.addBatch();}pst.executeBatch();conn.commit();conn.setAutoCommit(true);System.out.println("Insert " + max + " record cost :" + ((System.currentTimeMillis() - start) / 1000) + " ; Insert Speed:" + (max / ((System.currentTimeMillis() - start) / 1000)));conn.close();} catch (Exception ex) {ex.printStackTrace();}}public static void mongodb() {try {MongoClient mongoClient = new MongoClient("localhost", 27017);DB db = mongoClient.getDB("demo");boolean auth = db.authenticate("root", "root".toCharArray());System.out.println("Connect to database successfully");System.out.println("Authentication: " + auth);Set<String> tables = db.getCollectionNames();for (String name : tables) {System.out.println("Table : " + name);}DBCollection demo = db.getCollection("demo");long start = System.currentTimeMillis();for (int n = 0; n < max; n++) {DBObject dbo = new BasicDBObject();dbo.put("name", "Name" + Math.random());dbo.put("date", new Date());demo.insert(dbo);}System.out.println("Insert " + max + " record cost :" + ((System.currentTimeMillis() - start) / 1000) + " ; Insert Speed:" + (max / ((System.currentTimeMillis() - start) / 1000)));} catch (Exception e) {System.err.println(e.getClass().getName() + ": " + e.getMessage());}}
测试输出结果:
Insert 100000 record cost :22 ; Insert Speed:4545Connect to database successfullyAuthentication: trueTable : demoTable : system.indexesTable : system.usersInsert 100000 record cost :12 ; Insert Speed:8333
当然这个比排除磁盘性能的影响。MySQL是采用默认的InnoDB模式,所以在存储上可能也会有点压力;
0 0
- Mysql5 与 Mongodb2.4 简单性能对比
- MYSQL5.5和MYSQL5.1性能对比
- 原生代码与托管代码的一个简单性能对比
- [原创] pycurl简单用法与urllib2性能对比
- MongoDB简单查询与复杂查询性能对比
- java rmi 与 spring mvc rest 性能简单对比
- Percona 5.5.16与官方MySQL5.5.16的简单TPS对比
- 虚拟机性能测试与对比
- datediff 与 date_format 性能对比
- XmlDocumnt与XPathDocument性能对比
- currenthashmap 与 ehcache 性能对比
- log4j 与 logback 性能对比
- oracle与mysql性能对比
- pthread_spinlock_t与pthread_mutex_t性能对比
- 红黑树与小根堆性能对比
- Memcached与OCS性能对比
- 信号量与互斥锁性能对比
- ADO与EF性能对比
- java日期 时间
- 澎湃的圣诞行情后,迎来元旦行情 2
- SQLite3命令操作与使用总结
- timesten:TT0802错误
- 关于Android中xListView所出现的问题(点击后程序崩掉)
- Mysql5 与 Mongodb2.4 简单性能对比
- Chapter 7 Caches
- [转载]table合并单元格 colspan(跨列)和rowspan(跨行)
- Adroid中广播接收者的使用,实现强制下线功能
- Openwrt
- 计算机网络术语详解
- msysgit安装与配置
- iOS开发_统计xcode代码行数
- [LeetCode] Recover Binary Search Tree