public class Main {
public static void main(String[] args)throws Exception{
float x=3000;
float y=0;
long t1=System.currentTimeMillis();
// for(int i=0;i<1000000000L;i++) {
// y=x+x+x+x+x;//就十亿次运算而言加法运算才能稍微看得出来比乘法慢一点点:380/410
y=x*5;
// }
// for(int i=0;i<2000000000L;i++) {
// y=x*0.2*0.2;
// y=x/5/5;//乘除运行时间几乎没有差别800/800
// }
// for(int i=0;i<2000000000L;i++) {
// y=x+3000;
y=x-3000;//加减法对比:776/780,几乎没差
// }
// for(int i=0;i<3000000000L;i++) {
y=x+3000;
// y=x/15;//加法和除法:780/780,几乎没有差别
// }
long t2=System.currentTimeMillis();
System.out.println(t2-t1);
}
}
某本书里