fork(3) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. System.out.println((-10) >>> 1);
  13. System.out.println((-10) >> 1);
  14. System.out.println((-11) >> 1);
  15. System.out.println((-11) / 2);
  16. for (int x = -10; x < 10; ++x)
  17. {
  18. if (((x - (x >> 31)) >> 1) != x / 2) System.out.println("Not equal for: " + x);
  19. }
  20.  
  21. int bounds = 10000000;
  22. long start = System.nanoTime();
  23. for (int i = -bounds; i < bounds; ++i)
  24. {
  25. int r = ((i - (i >> 31)) >> 1);
  26. }
  27. long run1 = System.nanoTime() - start;
  28. start = System.nanoTime();
  29. for (int i = -bounds; i < bounds; ++i)
  30. {
  31. int r = i / 2;
  32. }
  33. long run2 = System.nanoTime() - start;
  34.  
  35. System.out.printf("Run 1: %10d\n", run1);
  36. System.out.printf("Run 2: %10d\n", run2);
  37. }
  38. }
Success #stdin #stdout 0.52s 380352KB
stdin
Standard input is empty
stdout
2147483643
-5
-6
-5
Run 1:   40056326
Run 2:  414360548