fork(2) download
  1. class Volatile
  2. {
  3. private volatile static int ile1 = 0;
  4. private static int ile2 = 0;
  5. //------------------------
  6. public static void main(String[] args)
  7. {
  8. int ileRazy = 10000;
  9. try
  10. {
  11. ileRazy = Integer.parseInt(args[0]);
  12. }
  13. catch(Exception e)
  14. {
  15. }
  16. long start = System.nanoTime();
  17. for(int i=0;i<ileRazy;i++)
  18. {
  19. compute1();
  20. }
  21. long end = System.nanoTime();
  22. System.out.println("Przesuwanie volatile "+(end-start)/Math.pow(10,6));
  23.  
  24. start = System.nanoTime();
  25. for(int i=0;i<ileRazy;i++)
  26. {
  27. compute2();
  28. }
  29. end = System.nanoTime();
  30. System.out.println("Dzielenie volatile "+(end-start)/Math.pow(10,6));
  31.  
  32. start = System.nanoTime();
  33. for(int i=0;i<ileRazy;i++)
  34. {
  35. compute3();
  36. }
  37. end = System.nanoTime();
  38. System.out.println("Przesuwanie "+(end-start)/Math.pow(10,6));
  39.  
  40. start = System.nanoTime();
  41. for(int i=0;i<ileRazy;i++)
  42. {
  43. compute4();
  44. }
  45. end = System.nanoTime();
  46. System.out.println("Dzielenie "+(end-start)/Math.pow(10,6));
  47. }
  48. //------------------------
  49. private static void compute1()
  50. {
  51. for(int i=0;i<666;i++)
  52. {
  53. ile1 = i >> 1;
  54. }
  55. }
  56. //------------------------
  57. private static void compute2()
  58. {
  59. for(int i=0;i<666;i++)
  60. {
  61. ile1 = i/2;
  62. }
  63. }
  64. //------------------------
  65. private static void compute3()
  66. {
  67. for(int i=0;i<666;i++)
  68. {
  69. ile2 = i >> 1;
  70. }
  71. }
  72. //------------------------
  73. private static void compute4()
  74. {
  75. for(int i=0;i<666;i++)
  76. {
  77. ile2 = i/2;
  78. }
  79. }
  80. }
Success #stdin #stdout 0.41s 320704KB
stdin
Standard input is empty
stdout
Przesuwanie volatile 64.848135
Dzielenie volatile 132.449981
Przesuwanie 9.188282
Dzielenie 110.473564