Advertisement
karlicoss

cache line size java

Aug 24th, 2014
499
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.67 KB | None | 0 0
  1. public class CacheLine {
  2.     public static final int CACHE_LINE_SIZE = 64;
  3.     public static final int SIZE = 1024 * 1024 * 1024;
  4.     public static void main(String[] args) {
  5.         new CacheLine().run();
  6.     }
  7.  
  8.     private void test(byte[] a, int step, int count) {
  9.         long startTime = System.currentTimeMillis();
  10.         for (int qq = 0; qq < 50; qq++) {
  11.             for (int i = 0, pos = 0; i < count; i += 1, pos += step) {
  12.                 a[pos] += 1;
  13.             }
  14.         }
  15.         long endTime = System.currentTimeMillis();
  16.         System.err.println(String.format("Step %d, time %d ms", step, endTime - startTime));
  17.     }
  18.  
  19.     private void run() {
  20.         byte[] aaa = new byte[SIZE];
  21.         int step = 4;
  22.         for (int cstep = step; cstep < 512; cstep += step) {
  23.             test(aaa, cstep, 1024 * 1024);
  24.         }
  25.     }
  26. }
  27.  
  28. Step 4, time 38 ms
  29. Step 8, time 50 ms
  30. Step 12, time 61 ms
  31. Step 16, time 82 ms
  32. Step 20, time 104 ms
  33. Step 24, time 124 ms
  34. Step 28, time 150 ms
  35. Step 32, time 167 ms
  36. Step 36, time 189 ms
  37. Step 40, time 212 ms
  38. Step 44, time 233 ms
  39. Step 48, time 258 ms
  40. Step 52, time 283 ms
  41. Step 56, time 306 ms
  42. Step 60, time 331 ms
  43. Step 64, time 352 ms
  44. Step 68, time 362 ms
  45. Step 72, time 373 ms
  46. Step 76, time 380 ms
  47. Step 80, time 396 ms
  48. Step 84, time 410 ms
  49. Step 88, time 417 ms
  50. Step 92, time 427 ms
  51. Step 96, time 435 ms
  52. Step 100, time 446 ms
  53. Step 104, time 449 ms
  54. Step 108, time 454 ms
  55. Step 112, time 461 ms
  56. Step 116, time 462 ms
  57. Step 120, time 471 ms
  58. Step 124, time 494 ms
  59. Step 128, time 492 ms
  60. Step 132, time 475 ms
  61. Step 136, time 480 ms
  62. Step 140, time 477 ms
  63. Step 144, time 477 ms
  64. Step 148, time 478 ms
  65. Step 152, time 481 ms
  66. Step 156, time 473 ms
  67. Step 160, time 479 ms
  68. Step 164, time 477 ms
  69. Step 168, time 481 ms
  70. Step 172, time 480 ms
  71. Step 176, time 478 ms
  72. Step 180, time 477 ms
  73. Step 184, time 478 ms
  74. Step 188, time 483 ms
  75. Step 192, time 477 ms
  76. Step 196, time 477 ms
  77. Step 200, time 480 ms
  78. Step 204, time 481 ms
  79. Step 208, time 487 ms
  80. Step 212, time 477 ms
  81. Step 216, time 479 ms
  82. Step 220, time 482 ms
  83. Step 224, time 488 ms
  84. Step 228, time 482 ms
  85. Step 232, time 484 ms
  86. Step 236, time 532 ms
  87. Step 240, time 496 ms
  88. Step 244, time 491 ms
  89. Step 248, time 482 ms
  90. Step 252, time 493 ms
  91. Step 256, time 514 ms
  92. Step 260, time 512 ms
  93. Step 264, time 512 ms
  94. Step 268, time 519 ms
  95. Step 272, time 506 ms
  96. Step 276, time 505 ms
  97. Step 280, time 532 ms
  98. Step 284, time 516 ms
  99. Step 288, time 520 ms
  100. Step 292, time 514 ms
  101. Step 296, time 510 ms
  102. Step 300, time 537 ms
  103. Step 304, time 522 ms
  104. Step 308, time 554 ms
  105. Step 312, time 559 ms
  106. Step 316, time 549 ms
  107. Step 320, time 548 ms
  108. Step 324, time 546 ms
  109. Step 328, time 553 ms
  110. Step 332, time 567 ms
  111. Step 336, time 549 ms
  112. Step 340, time 546 ms
  113. Step 344, time 526 ms
  114. Step 348, time 526 ms
  115. Step 352, time 500 ms
  116. Step 356, time 504 ms
  117. Step 360, time 494 ms
  118. Step 364, time 493 ms
  119. Step 368, time 495 ms
  120. Step 372, time 463 ms
  121. Step 376, time 483 ms
  122. Step 380, time 481 ms
  123. Step 384, time 468 ms
  124. Step 388, time 466 ms
  125. Step 392, time 498 ms
  126. Step 396, time 476 ms
  127. Step 400, time 491 ms
  128. Step 404, time 502 ms
  129. Step 408, time 499 ms
  130. Step 412, time 468 ms
  131. Step 416, time 579 ms
  132. Step 420, time 552 ms
  133. Step 424, time 487 ms
  134. Step 428, time 470 ms
  135. Step 432, time 459 ms
  136. Step 436, time 466 ms
  137. Step 440, time 467 ms
  138. Step 444, time 462 ms
  139. Step 448, time 447 ms
  140. Step 452, time 460 ms
  141. Step 456, time 448 ms
  142. Step 460, time 427 ms
  143. Step 464, time 462 ms
  144. Step 468, time 463 ms
  145. Step 472, time 469 ms
  146. Step 476, time 465 ms
  147. Step 480, time 457 ms
  148. Step 484, time 467 ms
  149. Step 488, time 458 ms
  150. Step 492, time 469 ms
  151. Step 496, time 461 ms
  152. Step 500, time 459 ms
  153. Step 504, time 426 ms
  154. Step 508, time 469 ms
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement