diff options
Diffstat (limited to 'store/src/jmh/java/org/eclipse/viatra/solver/data/map/benchmarks/ImmutablePutBenchmark.java')
-rw-r--r-- | store/src/jmh/java/org/eclipse/viatra/solver/data/map/benchmarks/ImmutablePutBenchmark.java | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/store/src/jmh/java/org/eclipse/viatra/solver/data/map/benchmarks/ImmutablePutBenchmark.java b/store/src/jmh/java/org/eclipse/viatra/solver/data/map/benchmarks/ImmutablePutBenchmark.java new file mode 100644 index 00000000..f0af443f --- /dev/null +++ b/store/src/jmh/java/org/eclipse/viatra/solver/data/map/benchmarks/ImmutablePutBenchmark.java | |||
@@ -0,0 +1,77 @@ | |||
1 | package org.eclipse.viatra.solver.data.map.benchmarks; | ||
2 | |||
3 | import java.util.ArrayList; | ||
4 | import java.util.HashMap; | ||
5 | import java.util.concurrent.TimeUnit; | ||
6 | |||
7 | import org.openjdk.jmh.annotations.Benchmark; | ||
8 | import org.openjdk.jmh.annotations.BenchmarkMode; | ||
9 | import org.openjdk.jmh.annotations.Fork; | ||
10 | import org.openjdk.jmh.annotations.Measurement; | ||
11 | import org.openjdk.jmh.annotations.Mode; | ||
12 | import org.openjdk.jmh.annotations.OutputTimeUnit; | ||
13 | import org.openjdk.jmh.annotations.Warmup; | ||
14 | import org.openjdk.jmh.infra.Blackhole; | ||
15 | |||
16 | @Fork(1) | ||
17 | @BenchmarkMode(Mode.AverageTime) | ||
18 | @OutputTimeUnit(TimeUnit.MILLISECONDS) | ||
19 | @Measurement(time = 1, timeUnit = TimeUnit.SECONDS) | ||
20 | @Warmup(time = 1, timeUnit = TimeUnit.SECONDS) | ||
21 | public class ImmutablePutBenchmark { | ||
22 | @Benchmark | ||
23 | public void immutablePutBenchmark(ImmutablePutExecutionPlan executionPlan, Blackhole blackhole) { | ||
24 | var sut = executionPlan.createSut(); | ||
25 | for (int i = 0; i < executionPlan.nPut; i++) { | ||
26 | sut.put(executionPlan.nextKey(), executionPlan.nextValue()); | ||
27 | } | ||
28 | blackhole.consume(sut); | ||
29 | } | ||
30 | |||
31 | @Benchmark | ||
32 | public void immutablePutAndCommitBenchmark(ImmutablePutExecutionPlan executionPlan, Blackhole blackhole) { | ||
33 | var sut = executionPlan.createSut(); | ||
34 | for (int i = 0; i < executionPlan.nPut; i++) { | ||
35 | sut.put(executionPlan.nextKey(), executionPlan.nextValue()); | ||
36 | if (i % 10 == 0) { | ||
37 | blackhole.consume(sut.commit()); | ||
38 | } | ||
39 | } | ||
40 | blackhole.consume(sut); | ||
41 | } | ||
42 | |||
43 | @Benchmark | ||
44 | public void baselinePutBenchmark(ImmutablePutExecutionPlan executionPlan, Blackhole blackhole) { | ||
45 | var sut = new HashMap<Integer, String>(); | ||
46 | for (int i = 0; i < executionPlan.nPut; i++) { | ||
47 | var key = executionPlan.nextKey(); | ||
48 | var value = executionPlan.nextValue(); | ||
49 | if (executionPlan.isDefault(value)) { | ||
50 | sut.remove(key); | ||
51 | } else { | ||
52 | sut.put(key, value); | ||
53 | } | ||
54 | } | ||
55 | blackhole.consume(sut); | ||
56 | } | ||
57 | |||
58 | @Benchmark | ||
59 | public void baselinePutAndCommitBenchmark(ImmutablePutExecutionPlan executionPlan, Blackhole blackhole) { | ||
60 | var sut = new HashMap<Integer, String>(); | ||
61 | var store = new ArrayList<HashMap<Integer, String>>(); | ||
62 | for (int i = 0; i < executionPlan.nPut; i++) { | ||
63 | var key = executionPlan.nextKey(); | ||
64 | var value = executionPlan.nextValue(); | ||
65 | if (executionPlan.isDefault(value)) { | ||
66 | sut.remove(key); | ||
67 | } else { | ||
68 | sut.put(key, value); | ||
69 | } | ||
70 | if (i % 10 == 0) { | ||
71 | store.add(new HashMap<>(sut)); | ||
72 | } | ||
73 | } | ||
74 | blackhole.consume(sut); | ||
75 | blackhole.consume(store); | ||
76 | } | ||
77 | } | ||