日期:2014-05-16 浏览次数:20614 次
?
core2 P8400, 4G mem
?
我的测试100W记录,mysql使用缺省安装,java -server -Xms2048M -Xmx2048M
hibernate
insert 1000000 count, consume 521.133 seconds
jdbc
insert 1000000 count, consume 508.46 seconds
?
select count(*) from APP_USER; 1000000 rows, 0.31 seconds;
?
结构APP_USER(ID, NAME, PASSWORD)
写入数据i: insert into APP_USER(NAME, PASSWORD) values(String.valueOf(i),?String.valueOf(i));
?
?
可见Hibernate性能并不太慢。大约损失性能2.75%还是可以接受,如果对性能苛刻的要求建议还是直接jdbc吧。
?
@Test @Transactional(propagation = Propagation.REQUIRES_NEW) public void testHibernate() { logger.info("start test Hibernate..."); long begin = System.currentTimeMillis(); baseDao.saveOrUpdateAll(users); long end = System.currentTimeMillis(); logger.info("insert " + num + " count, consume " + (end - begin) / 1000f + " seconds"); }?
@Test @Transactional(propagation = Propagation.REQUIRES_NEW) public void testJdbc() { logger.info("start test jdbc..."); long begin = System.currentTimeMillis(); jdbcTemplate.batchUpdate("insert into APP_USER(NAME, PASSWORD) values (?, ?)", new BatchPreparedStatementSetter() { @Override public void setValues(PreparedStatement ps, int row) throws SQLException { User user = users.get(row); ps.setString(1, user.getName()); ps.setString(2, user.getPassword()); } @Override public int getBatchSize() { return users.size(); } }); long end = System.currentTimeMillis(); logger.info("insert " + num + " count, consume " + (end - begin) / 1000f + " seconds"); }
?
我一直觉得Hibernate的性能不会很差,我只用他做映射,一般不搞继承、所有关系只用ID而不用对象做对应。
今天测试510W数据从数据库(表实际有3700W记录)加载到内存中:java参数 -server -Xms2048M -Xmx2048M
?
?
?
?
?