代码:
package test2;
public class _movingright {
public static void main(String[] args) {
int num = -10001;
long temp = System.nanoTime();
System.out.println(num = num/2);
System.out.println(System.nanoTime()-temp);
num = -10001;
temp = System.nanoTime();
System.out.println(num = num>>1+1);
System.out.println(System.nanoTime()-temp);
}
}
运行结果
-5000
149849
-2501
14369
奇怪的是,写循环多次运行之后发现几乎没有差别:
package test2;
public class _movingright {
public static void main(String[] args) {
int times = 5000;
long [] divide = new long [times];
long [] moveright = new long [times];
for (int i=0;i<times;i++) {
int num = 10000;
long temp = System.nanoTime();
num = num/2;
divide[i] = (lo