The performance between the 'normal' operation and the 'shift' operation.
First, I gonna post my test result with some code:
1 //test the peformance of the <normal operation> and the <shift operation>. 2 class ShiftOperation 3 { 4 public static void main(String[] args) 5 { 6 long startTime1 = System.nanoTime(); 7 for(long i = 0; i < 10000000000L; i++){ 8 int temp = 128 * 128; 9 } 10 long endTime1 = System.nanoTime(); 11 System.out.println("elapse = " + (endTime1 - startTime1) + " ns"); 12 //outputs:elapse = 13265249285 ns 13 14 long startTime2 = System.nanoTime(); 15 for(long i = 0; i < 10000000000L; i++){ 16 int temp = 128 << 8; 17 } 18 long endTime2 = System.nanoTime(); 19 System.out.println("elapse = " + (endTime2 - startTime2) + " ns"); 20 //outputs:elapse = 12723663971 ns 21 } 22 }
The below screen shot shows the simple steps of the operations between the two.


浙公网安备 33010602011771号