diff options
author | 2021-07-30 20:03:33 +0200 | |
---|---|---|
committer | 2021-07-30 20:03:33 +0200 | |
commit | 532d2045f5f87e9049475ddd055c7a93ea38dca0 (patch) | |
tree | c7585eba98c27fbda93fcdff177056def0a0cf71 /model-data/src | |
parent | Replaced platformURI with projectMapping to fix genmodel error. (diff) | |
download | refinery-532d2045f5f87e9049475ddd055c7a93ea38dca0.tar.gz refinery-532d2045f5f87e9049475ddd055c7a93ea38dca0.tar.zst refinery-532d2045f5f87e9049475ddd055c7a93ea38dca0.zip |
Add JMH benchmarks for model-data
Diffstat (limited to 'model-data/src')
2 files changed, 133 insertions, 0 deletions
diff --git a/model-data/src/jmh/java/org/eclipse/viatra/solver/data/map/benchmarks/ImmutablePutBenchmark.java b/model-data/src/jmh/java/org/eclipse/viatra/solver/data/map/benchmarks/ImmutablePutBenchmark.java new file mode 100644 index 00000000..f0af443f --- /dev/null +++ b/model-data/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 | } | ||
diff --git a/model-data/src/jmh/java/org/eclipse/viatra/solver/data/map/benchmarks/ImmutablePutExecutionPlan.java b/model-data/src/jmh/java/org/eclipse/viatra/solver/data/map/benchmarks/ImmutablePutExecutionPlan.java new file mode 100644 index 00000000..6cac74af --- /dev/null +++ b/model-data/src/jmh/java/org/eclipse/viatra/solver/data/map/benchmarks/ImmutablePutExecutionPlan.java | |||
@@ -0,0 +1,56 @@ | |||
1 | package org.eclipse.viatra.solver.data.map.benchmarks; | ||
2 | |||
3 | import java.util.Random; | ||
4 | |||
5 | import org.eclipse.viatra.solver.data.map.ContinousHashProvider; | ||
6 | import org.eclipse.viatra.solver.data.map.VersionedMapStore; | ||
7 | import org.eclipse.viatra.solver.data.map.VersionedMapStoreImpl; | ||
8 | import org.eclipse.viatra.solver.data.map.internal.VersionedMapImpl; | ||
9 | import org.eclipse.viatra.solver.data.map.tests.utils.MapTestEnvironment; | ||
10 | import org.openjdk.jmh.annotations.Level; | ||
11 | import org.openjdk.jmh.annotations.Param; | ||
12 | import org.openjdk.jmh.annotations.Scope; | ||
13 | import org.openjdk.jmh.annotations.Setup; | ||
14 | import org.openjdk.jmh.annotations.State; | ||
15 | |||
16 | @State(Scope.Benchmark) | ||
17 | public class ImmutablePutExecutionPlan { | ||
18 | |||
19 | @Param({ "100", "10000" }) | ||
20 | public int nPut; | ||
21 | |||
22 | @Param({ "32", "1000", "100000" }) | ||
23 | public int nKeys; | ||
24 | |||
25 | @Param({ "2", "3" }) | ||
26 | public int nValues; | ||
27 | |||
28 | private Random random; | ||
29 | |||
30 | private String[] values; | ||
31 | |||
32 | private ContinousHashProvider<Integer> hashProvider = MapTestEnvironment.prepareHashProvider(false); | ||
33 | |||
34 | @Setup(Level.Trial) | ||
35 | public void setUpTrial() { | ||
36 | random = new Random(); | ||
37 | values = MapTestEnvironment.prepareValues(nValues); | ||
38 | } | ||
39 | |||
40 | public VersionedMapImpl<Integer, String> createSut() { | ||
41 | VersionedMapStore<Integer, String> store = new VersionedMapStoreImpl<Integer, String>(hashProvider, values[0]); | ||
42 | return (VersionedMapImpl<Integer, String>) store.createMap(); | ||
43 | } | ||
44 | |||
45 | public Integer nextKey() { | ||
46 | return random.nextInt(nKeys); | ||
47 | } | ||
48 | |||
49 | public boolean isDefault(String value) { | ||
50 | return value == values[0]; | ||
51 | } | ||
52 | |||
53 | public String nextValue() { | ||
54 | return values[random.nextInt(nValues)]; | ||
55 | } | ||
56 | } | ||