Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. import org.openjdk.jmh.annotations.*;
  2. import sun.misc.Contended;
  3.  
  4.  
  5. @Fork(value = 1, jvmArgsPrepend = "-XX:-RestrictContended")
  6. @Warmup(iterations = 10)
  7. @Measurement(iterations = 30)
  8. @Threads(2)
  9. public class ContendedBenchmarks {
  10.  
  11. @State(Scope.Group)
  12. public static class Unpadded {
  13. public long a;
  14. public long b;
  15. }
  16.  
  17. @State(Scope.Group)
  18. public static class Padded {
  19. @Contended
  20. public long a;
  21. public long b;
  22. }
  23.  
  24. @Group("unpadded")
  25. @GroupThreads(1)
  26. @Benchmark
  27. public long updateUnpaddedA(Unpadded u) {
  28. return u.a++;
  29. }
  30.  
  31. @Group("unpadded")
  32. @GroupThreads(1)
  33. @Benchmark
  34. public long updateUnpaddedB(Unpadded u) {
  35. return u.b++;
  36. }
  37.  
  38. @Group("padded")
  39. @GroupThreads(1)
  40. @Benchmark
  41. public long updatePaddedA(Padded u) {
  42. return u.a++;
  43. }
  44.  
  45. @Group("padded")
  46. @GroupThreads(1)
  47. @Benchmark
  48. public long updatePaddedB(Padded u) {
  49. return u.b++;
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement