62,614
社区成员
发帖
与我相关
我的任务
分享
int x = 1, y;
y = 0;
long time;
for(int k=0; k<8; k++) {
time = System.currentTimeMillis();
for(long j=0; j<2000000000; j++)
y = 2 * x;
System.out.println("所用时间1:" + (System.currentTimeMillis() - time));
time = System.currentTimeMillis();
for(long j=0; j<2000000000; j++)
y = x << 1;
System.out.println("所用时间2:" + (System.currentTimeMillis() - time));
System.out.println();
}
int x = 1, y;
y = 0;
long time;
for(int k=0; k<8; k++) {
time = System.currentTimeMillis();
for(long j=0; j<2000000000; j++)
y = x << 1;
System.out.println("所用时间1:" + (System.currentTimeMillis() - time));
time = System.currentTimeMillis();
for(long j=0; j<2000000000; j++)
y = 2 * x;
System.out.println("所用时间2:" + (System.currentTimeMillis() - time));
System.out.println();
}
package test;
public class Test {
public static void main(String[] args) {
for (int k =0; k<Integer.MAX_VALUE; k++)
;
}
}
public static void main(java.lang.String[]);
Code:
Stack=2, Locals=2, Args_size=1
0: iconst_0
1: istore_1
2: goto 8
5: iinc 1, 1
8: iload_1
9: ldc #16; //int 2147483647
11: if_icmplt 5
14: return
LineNumberTable:
line 5: 0
line 8: 14
LocalVariableTable:
Start Length Slot Name Signature
0 15 0 args [Ljava/lang/String;
2 12 1 k I
package test;
public class Test {
public static void main(String[] args) {
for (int k =Integer.MAX_VALUE; k>0; k--)
;
}
}
public static void main(java.lang.String[]);
Code:
Stack=1, Locals=2, Args_size=1
0: ldc #16; //int 2147483647
2: istore_1
3: goto 9
6: iinc 1, -1
9: iload_1
10: ifgt 6
13: return
LineNumberTable:
line 5: 0
line 8: 13
LocalVariableTable:
Start Length Slot Name Signature
0 14 0 args [Ljava/lang/String;
3 10 1 k I
//for (int k =0; k<Integer.MAX_VALUE; k++)
5: iinc 1, 1
8: iload_1
9: ldc #16; //int 2147483647
11: if_icmplt 5
//for (int k =Integer.MAX_VALUE; k>0; k--)
6: iinc 1, -1
9: iload_1
10: ifgt 6