Java直接内存与非直接内存性能测试

发表于:2016-3-14 11:29

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:xingoo    来源:51Testing软件测试网采编

分享:
  读写速度比较
  然后在写段代码,测试下读写的速度:
int time = 1000;
Date begin = new Date();
ByteBuffer buffer = ByteBuffer.allocate(2*time);
for(int i=0;i<time;i++){
buffer.putChar('a');
}
buffer.flip();
for(int i=0;i<time;i++){
buffer.getChar();
}
Date end = new Date();
System.out.println(end.getTime()-begin.getTime());
begin = new Date();
ByteBuffer buffer2 = ByteBuffer.allocateDirect(2*time);
for(int i=0;i<time;i++){
buffer2.putChar('a');
}
buffer2.flip();
for(int i=0;i<time;i++){
buffer2.getChar();
}
end = new Date();
System.out.println(end.getTime()-begin.getTime());
  测试的结果如下:
  可以看到直接内存在直接的IO操作上,还是有明显的差异的!
22/2<12
2023测试行业从业人员调查问卷已开启,千元大奖正在等你~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2023
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号