JAVA 右移一位比除以2快多少?

代码:
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>1;
			moveright[i] = (long) (System.nanoTime()-temp);
		}
		long sum1 = 0;
		long sum2 = 0;
		for (int i=0;i
1.064516129032258

(挠头?)


你可能感兴趣的:(JAVA 右移一位比除以2快多少?)