62,614
社区成员
发帖
与我相关
我的任务
分享
public class SecondsCalc {
public static void main(String[] args) {
long a = System.currentTimeMillis();
for(int i=0; i<5000000; i++){
if(1 < (7 * 24 * 60 * 60 * 1000)){ //改成if(1 < 604800000){ 执行时间反而更长了。何解????
// if(1 < 604800000){
System.out.println("ok" + i);
}
}
long b = System.currentTimeMillis();
System.out.println("time=" + (b-a));
}
}
public static void main(String[] args) {
int i=0;
if(i<3*7){
System.out.println("aaa");
}
if(1<3*7){
System.out.println("bbb");
}
}
编译之后,再反编译的代码如下:
public static void main(String[] args)
{
int i = 0;
if (i < 21) {
System.out.println("aaa");
}
System.out.println("bbb");
}
public static void main(String[] args)
{
long a = System.currentTimeMillis();
for (int i = 0; i < 5000000; ++i)
{
System.out.println("ok" + i);
}
long b = System.currentTimeMillis();
System.out.println("time=" + (b - a));
}
时间差,是由系统环境引起的,不是代码引起的 long a = System.currentTimeMillis();
long count = 0;
for(int i=0; i<500000000; i++){
if(1 < (7 * 24 * 60 * 60 * 1000)) { //改成if(1 < 604800000){ 执行时间反而更长了。何解????
// if(1 < 604800000){
// System.out.println("ok" + i);
count += i;
}
}
long b = System.currentTimeMillis();
System.out.println("count is :" + count + ". time=" + (b-a));