aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <marussy@mit.bme.hu>2021-07-30 20:03:33 +0200
committerLibravatar Kristóf Marussy <marussy@mit.bme.hu>2021-07-30 20:03:33 +0200
commit532d2045f5f87e9049475ddd055c7a93ea38dca0 (patch)
treec7585eba98c27fbda93fcdff177056def0a0cf71
parentReplaced platformURI with projectMapping to fix genmodel error. (diff)
downloadrefinery-532d2045f5f87e9049475ddd055c7a93ea38dca0.tar.gz
refinery-532d2045f5f87e9049475ddd055c7a93ea38dca0.tar.zst
refinery-532d2045f5f87e9049475ddd055c7a93ea38dca0.zip
Add JMH benchmarks for model-data
-rw-r--r--gradle.properties1
-rw-r--r--gradle/java-common.gradle4
-rw-r--r--gradle/jmh.gradle40
-rw-r--r--model-data/build.gradle1
-rw-r--r--model-data/src/jmh/java/org/eclipse/viatra/solver/data/map/benchmarks/ImmutablePutBenchmark.java77
-rw-r--r--model-data/src/jmh/java/org/eclipse/viatra/solver/data/map/benchmarks/ImmutablePutExecutionPlan.java56
6 files changed, 177 insertions, 2 deletions
diff --git a/gradle.properties b/gradle.properties
index 8b4f3793..542a8766 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -2,6 +2,7 @@ ecoreVersion=2.24.0
2ecoreCodegenVersion=2.26.0 2ecoreCodegenVersion=2.26.0
3hamcrestVersion=2.2 3hamcrestVersion=2.2
4jettyVersion=9.4.42.v20210604 4jettyVersion=9.4.42.v20210604
5jmhVersion=1.32
5junitVersion=5.7.2 6junitVersion=5.7.2
6mweVersion=1.6.1 7mweVersion=1.6.1
7mwe2Version=2.12.1 8mwe2Version=2.12.1
diff --git a/gradle/java-common.gradle b/gradle/java-common.gradle
index 24df4201..caae7d78 100644
--- a/gradle/java-common.gradle
+++ b/gradle/java-common.gradle
@@ -52,9 +52,9 @@ eclipse {
52 } 52 }
53 } 53 }
54 } 54 }
55 55
56 jdt.file.whenMerged { properties -> 56 jdt.file.whenMerged { properties ->
57 // Allow @SupperessWarnings to suppress SonalLint warnings 57 // Allow @SupperessWarnings to suppress SonarLint warnings
58 properties['org.eclipse.jdt.core.compiler.problem.unhandledWarningToken'] = 'ignore' 58 properties['org.eclipse.jdt.core.compiler.problem.unhandledWarningToken'] = 'ignore'
59 } 59 }
60} 60}
diff --git a/gradle/jmh.gradle b/gradle/jmh.gradle
new file mode 100644
index 00000000..ea88f3e3
--- /dev/null
+++ b/gradle/jmh.gradle
@@ -0,0 +1,40 @@
1configurations {
2 jmh {
3 extendsFrom compile
4 }
5}
6
7sourceSets {
8 jmh {
9 java.srcDirs = ['src/jmh/java']
10 resources.srcDirs = ['src/jmh/resources']
11 compileClasspath += sourceSets.main.runtimeClasspath
12 compileClasspath += sourceSets.test.runtimeClasspath
13 xtendOutputDir = 'src/jmh/xtend-gen'
14 }
15}
16
17dependencies {
18 jmhRuntime "org.openjdk.jmh:jmh-core:${jmhVersion}"
19 jmhCompile "org.openjdk.jmh:jmh-generator-annprocess:${jmhVersion}"
20 jmhAnnotationProcessor "org.openjdk.jmh:jmh-generator-annprocess:${jmhVersion}"
21}
22
23clean.doLast {
24 delete 'src/jmh/xtend-gen'
25}
26
27task jmh(type: JavaExec, dependsOn: jmhClasses) {
28 main = 'org.openjdk.jmh.Main'
29 classpath = sourceSets.jmh.compileClasspath + sourceSets.jmh.runtimeClasspath
30}
31
32eclipse.classpath {
33 plusConfigurations += [configurations.jmh]
34
35 // Allow test helper classes to be used in benchmarks from Eclipse.
36 file.whenMerged { classpath ->
37 def jmhClasspathEntry = classpath.entries.find { entry -> entry.path == 'src/jmh/java' }
38 jmhClasspathEntry.entryAttributes['test'] = true
39 }
40}
diff --git a/model-data/build.gradle b/model-data/build.gradle
index 49056339..56d64de9 100644
--- a/model-data/build.gradle
+++ b/model-data/build.gradle
@@ -1,4 +1,5 @@
1apply from: "${rootDir}/gradle/java-common.gradle" 1apply from: "${rootDir}/gradle/java-common.gradle"
2apply from: "${rootDir}/gradle/jmh.gradle"
2 3
3dependencies { 4dependencies {
4 testCompile "org.junit.jupiter:junit-jupiter-api:${junitVersion}" 5 testCompile "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
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 @@
1package org.eclipse.viatra.solver.data.map.benchmarks;
2
3import java.util.ArrayList;
4import java.util.HashMap;
5import java.util.concurrent.TimeUnit;
6
7import org.openjdk.jmh.annotations.Benchmark;
8import org.openjdk.jmh.annotations.BenchmarkMode;
9import org.openjdk.jmh.annotations.Fork;
10import org.openjdk.jmh.annotations.Measurement;
11import org.openjdk.jmh.annotations.Mode;
12import org.openjdk.jmh.annotations.OutputTimeUnit;
13import org.openjdk.jmh.annotations.Warmup;
14import 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)
21public 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 @@
1package org.eclipse.viatra.solver.data.map.benchmarks;
2
3import java.util.Random;
4
5import org.eclipse.viatra.solver.data.map.ContinousHashProvider;
6import org.eclipse.viatra.solver.data.map.VersionedMapStore;
7import org.eclipse.viatra.solver.data.map.VersionedMapStoreImpl;
8import org.eclipse.viatra.solver.data.map.internal.VersionedMapImpl;
9import org.eclipse.viatra.solver.data.map.tests.utils.MapTestEnvironment;
10import org.openjdk.jmh.annotations.Level;
11import org.openjdk.jmh.annotations.Param;
12import org.openjdk.jmh.annotations.Scope;
13import org.openjdk.jmh.annotations.Setup;
14import org.openjdk.jmh.annotations.State;
15
16@State(Scope.Benchmark)
17public 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}