From a155f6ba02e08a75ce6e474a86900b8363f506e8 Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Wed, 29 Sep 2021 02:45:57 +0200 Subject: build: migration to Gradle 7 --- .../data/map/benchmarks/ImmutablePutBenchmark.java | 77 ++++++++++++++++++++++ .../map/benchmarks/ImmutablePutExecutionPlan.java | 56 ++++++++++++++++ 2 files changed, 133 insertions(+) create mode 100644 store/src/jmh/java/org/eclipse/viatra/solver/data/map/benchmarks/ImmutablePutBenchmark.java create mode 100644 store/src/jmh/java/org/eclipse/viatra/solver/data/map/benchmarks/ImmutablePutExecutionPlan.java (limited to 'store/src/jmh/java/org/eclipse/viatra/solver/data') 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 @@ +package org.eclipse.viatra.solver.data.map.benchmarks; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.concurrent.TimeUnit; + +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Fork; +import org.openjdk.jmh.annotations.Measurement; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Warmup; +import org.openjdk.jmh.infra.Blackhole; + +@Fork(1) +@BenchmarkMode(Mode.AverageTime) +@OutputTimeUnit(TimeUnit.MILLISECONDS) +@Measurement(time = 1, timeUnit = TimeUnit.SECONDS) +@Warmup(time = 1, timeUnit = TimeUnit.SECONDS) +public class ImmutablePutBenchmark { + @Benchmark + public void immutablePutBenchmark(ImmutablePutExecutionPlan executionPlan, Blackhole blackhole) { + var sut = executionPlan.createSut(); + for (int i = 0; i < executionPlan.nPut; i++) { + sut.put(executionPlan.nextKey(), executionPlan.nextValue()); + } + blackhole.consume(sut); + } + + @Benchmark + public void immutablePutAndCommitBenchmark(ImmutablePutExecutionPlan executionPlan, Blackhole blackhole) { + var sut = executionPlan.createSut(); + for (int i = 0; i < executionPlan.nPut; i++) { + sut.put(executionPlan.nextKey(), executionPlan.nextValue()); + if (i % 10 == 0) { + blackhole.consume(sut.commit()); + } + } + blackhole.consume(sut); + } + + @Benchmark + public void baselinePutBenchmark(ImmutablePutExecutionPlan executionPlan, Blackhole blackhole) { + var sut = new HashMap(); + for (int i = 0; i < executionPlan.nPut; i++) { + var key = executionPlan.nextKey(); + var value = executionPlan.nextValue(); + if (executionPlan.isDefault(value)) { + sut.remove(key); + } else { + sut.put(key, value); + } + } + blackhole.consume(sut); + } + + @Benchmark + public void baselinePutAndCommitBenchmark(ImmutablePutExecutionPlan executionPlan, Blackhole blackhole) { + var sut = new HashMap(); + var store = new ArrayList>(); + for (int i = 0; i < executionPlan.nPut; i++) { + var key = executionPlan.nextKey(); + var value = executionPlan.nextValue(); + if (executionPlan.isDefault(value)) { + sut.remove(key); + } else { + sut.put(key, value); + } + if (i % 10 == 0) { + store.add(new HashMap<>(sut)); + } + } + blackhole.consume(sut); + blackhole.consume(store); + } +} diff --git a/store/src/jmh/java/org/eclipse/viatra/solver/data/map/benchmarks/ImmutablePutExecutionPlan.java b/store/src/jmh/java/org/eclipse/viatra/solver/data/map/benchmarks/ImmutablePutExecutionPlan.java new file mode 100644 index 00000000..6cac74af --- /dev/null +++ b/store/src/jmh/java/org/eclipse/viatra/solver/data/map/benchmarks/ImmutablePutExecutionPlan.java @@ -0,0 +1,56 @@ +package org.eclipse.viatra.solver.data.map.benchmarks; + +import java.util.Random; + +import org.eclipse.viatra.solver.data.map.ContinousHashProvider; +import org.eclipse.viatra.solver.data.map.VersionedMapStore; +import org.eclipse.viatra.solver.data.map.VersionedMapStoreImpl; +import org.eclipse.viatra.solver.data.map.internal.VersionedMapImpl; +import org.eclipse.viatra.solver.data.map.tests.utils.MapTestEnvironment; +import org.openjdk.jmh.annotations.Level; +import org.openjdk.jmh.annotations.Param; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.Setup; +import org.openjdk.jmh.annotations.State; + +@State(Scope.Benchmark) +public class ImmutablePutExecutionPlan { + + @Param({ "100", "10000" }) + public int nPut; + + @Param({ "32", "1000", "100000" }) + public int nKeys; + + @Param({ "2", "3" }) + public int nValues; + + private Random random; + + private String[] values; + + private ContinousHashProvider hashProvider = MapTestEnvironment.prepareHashProvider(false); + + @Setup(Level.Trial) + public void setUpTrial() { + random = new Random(); + values = MapTestEnvironment.prepareValues(nValues); + } + + public VersionedMapImpl createSut() { + VersionedMapStore store = new VersionedMapStoreImpl(hashProvider, values[0]); + return (VersionedMapImpl) store.createMap(); + } + + public Integer nextKey() { + return random.nextInt(nKeys); + } + + public boolean isDefault(String value) { + return value == values[0]; + } + + public String nextValue() { + return values[random.nextInt(nValues)]; + } +} -- cgit v1.2.3-70-g09d2