-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathClientDataBenchmark.java
More file actions
93 lines (82 loc) · 2.9 KB
/
ClientDataBenchmark.java
File metadata and controls
93 lines (82 loc) · 2.9 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package bwapi;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;
import java.util.SplittableRandom;
import java.util.stream.Collectors;
@Warmup(iterations = 3, time = 5)
@Measurement(iterations = 3, time = 5)
@Fork(3)
public class ClientDataBenchmark {
@State(Scope.Thread)
public static class EmptyState {
Client client;
Game game;
String[] strings;
@Setup(Level.Invocation)
public void setup() {
WrappedBuffer wrappedBuffer = new WrappedBuffer(ClientData.GameData.SIZE);
game = new Game();
game.botClientData().setBuffer(wrappedBuffer);
client = new Client(wrappedBuffer);
strings = buildStrings();
}
}
@State(Scope.Thread)
public static class FilledWithStrings {
Client client;
ClientData.GameData data;
Game game;
@Setup(Level.Invocation)
public void setup() {
WrappedBuffer wrappedBuffer = new WrappedBuffer(ClientData.GameData.SIZE);
game = new Game();
game.botClientData().setBuffer(wrappedBuffer);
client = new Client(wrappedBuffer);
data = game.botClientData().gameData();
String[] strings = buildStrings();
for (String s : strings) {
GameDataUtils.addString(client.liveClientData().gameData(), s);
}
}
}
private static String[] buildStrings() {
SplittableRandom rnd = new SplittableRandom(987654321L);
String[] strings = new String[GameDataUtils.MAX_COUNT];
for (int i = 0; i < strings.length; i++) {
strings[i] = rnd.ints(1022, 0, 9)
.mapToObj(Integer::toString)
.collect(Collectors.joining());
}
return strings;
}
@Benchmark
@Measurement(iterations = 2, time = 2)
@Warmup(time = 2)
@Fork(2)
public void reference(Blackhole blackhole) {
blackhole.consume(0);
}
@Benchmark
@OperationsPerInvocation(GameDataUtils.MAX_COUNT)
public int addUnitCommand(EmptyState s) {
for (int i = 0; i < GameDataUtils.MAX_COUNT; i++) {
s.game.addUnitCommand(0, 1, 2, 3, 4, 5);
}
return s.client.liveClientData().gameData().getCommandCount();
}
@Benchmark
@OperationsPerInvocation(GameDataUtils.MAX_COUNT)
public int addString(EmptyState s) {
for (int i = 0; i < GameDataUtils.MAX_COUNT; i++) {
GameDataUtils.addString(s.client.liveClientData().gameData(), s.strings[i]);
}
return s.client.liveClientData().gameData().getStringCount();
}
@Benchmark
@OperationsPerInvocation(GameDataUtils.MAX_COUNT)
public void getString(FilledWithStrings s, Blackhole blackhole) {
for (int i = 0; i < GameDataUtils.MAX_COUNT; i++) {
blackhole.consume(s.data.getStrings(i));
}
}
}