27
27
28
28
import org .openjdk .jmh .annotations .Benchmark ;
29
29
import org .openjdk .jmh .annotations .BenchmarkMode ;
30
+ import org .openjdk .jmh .annotations .Fork ;
31
+ import org .openjdk .jmh .annotations .Measurement ;
30
32
import org .openjdk .jmh .annotations .Mode ;
31
33
import org .openjdk .jmh .annotations .OutputTimeUnit ;
32
34
import org .openjdk .jmh .annotations .Param ;
33
35
import org .openjdk .jmh .annotations .Scope ;
34
36
import org .openjdk .jmh .annotations .Setup ;
35
37
import org .openjdk .jmh .annotations .State ;
36
38
import org .openjdk .jmh .annotations .Threads ;
39
+ import org .openjdk .jmh .annotations .Warmup ;
37
40
import org .openjdk .jmh .infra .Blackhole ;
38
41
39
42
@ State (Scope .Benchmark )
40
43
@ Threads (Threads .MAX )
44
+ @ Warmup (iterations = 4 , time = 2 )
45
+ @ Measurement (iterations = 4 , time = 2 )
46
+ @ Fork (value = 3 )
41
47
public class MonitorBench {
42
48
43
- @ Param ({"100" , "250" })
44
- int consumeUnlocked ;
45
-
46
- @ Param ({"100" , "250" })
47
- int consumeLocked ;
49
+ @ Param ({"50" /* , "250" */ })
50
+ int consumeTime ;
48
51
49
52
@ Param ({"0" , "1" })
50
53
int throwThreshold ;
@@ -67,19 +70,19 @@ public void setup() {
67
70
68
71
int update2 (int sharedIndex ) throws Exception {
69
72
synchronized (sharedLocks [sharedIndex ]) {
70
- Blackhole .consumeCPU (consumeLocked );
73
+ Blackhole .consumeCPU (consumeTime );
71
74
if (ThreadLocalRandom .current ().nextInt (range ) < throwThreshold ) {
72
75
throw new Exception ("Update failed" );
73
76
} else {
74
- Blackhole .consumeCPU (consumeLocked );
77
+ Blackhole .consumeCPU (consumeTime );
75
78
return 0 ;
76
79
}
77
80
}
78
81
}
79
82
80
83
int update1 (int sharedIndex ) throws Exception {
81
84
synchronized (sharedLocks [sharedIndex ]) {
82
- Blackhole .consumeCPU (consumeLocked );
85
+ Blackhole .consumeCPU (consumeTime );
83
86
return update2 (sharedIndex );
84
87
}
85
88
}
@@ -88,7 +91,7 @@ int update1(int sharedIndex) throws Exception {
88
91
@ BenchmarkMode (Mode .Throughput )
89
92
@ OutputTimeUnit (TimeUnit .MILLISECONDS )
90
93
public int action () throws InterruptedException {
91
- Blackhole .consumeCPU (consumeUnlocked );
94
+ Blackhole .consumeCPU (consumeTime );
92
95
int sharedLockIndex = ThreadLocalRandom .current ().nextInt (locksSize );
93
96
Object sharedLock = sharedLocks [sharedLockIndex ];
94
97
synchronized (sharedLock ) {
0 commit comments