1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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<Integer, String>();
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<Integer, String>();
var store = new ArrayList<HashMap<Integer, String>>();
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);
}
}
|