67,514
社区成员
发帖
与我相关
我的任务
分享
double before = System.currentTimeMillis();
for (int i = 0; i < 100000000; i++) {
BigDecimal d = new BigDecimal("0");
}
double after = System.currentTimeMillis();
System.out.println(after-before);
before = System.currentTimeMillis();
BigDecimal d;
for (int i = 0; i < 100000000; i++) {
d = new BigDecimal("0");
}
after = System.currentTimeMillis();
System.out.println(after-before);
输出:
7353.0
7005.0
所以没啥大区别,肯定不是倍数关系。主要开销都在创建对象上,相差的这.3秒应该是创建局部变量引用的开销