-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBenchmarkBrownianMotion.java
More file actions
162 lines (131 loc) · 4.08 KB
/
Copy pathBenchmarkBrownianMotion.java
File metadata and controls
162 lines (131 loc) · 4.08 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package com.aivean.testrecarr;
import com.aivean.recarr.RecordArray;
import org.openjdk.jmh.annotations.*;
import java.util.concurrent.TimeUnit;
@BenchmarkMode(Mode.AverageTime)
@State(Scope.Thread)
@Fork(1)
@Warmup(iterations = 5, time = 2/* seconds */)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@Measurement(iterations = 5, time = 4/* seconds */)
public class BenchmarkBrownianMotion {
/*
Benchmark (n) (p2pCols) (recImpl) Mode Cnt Score Error Units
BenchmarkBrownianMotion.simulate 10000 false false avgt 5 0.053 ± 0.005 ms/op
BenchmarkBrownianMotion.simulate 10000 false true avgt 5 0.032 ± 0.001 ms/op
BenchmarkBrownianMotion.simulate 10000 true false avgt 5 71.456 ± 4.416 ms/op
BenchmarkBrownianMotion.simulate 10000 true true avgt 5 58.539 ± 1.728 ms/op
*/
@Param({"10000"})
public int n;
@Param({"false", "true"})
public boolean recImpl;
@Param({"false", "true"})
public boolean p2pCols;
PointGameSimulator simulator;
@Setup
public void setup() {
if (recImpl) {
simulator = new PointGameSimulator() {
final int nPoints = n;
final RecordArray<PointGameSimulator.Point2D> points = RecordArray.create(Point2D.class, nPoints);
@Override
int getNumPoints() {
return nPoints;
}
@Override
Point2D getPoint(int index) {
return points.get(index);
}
@Override
void simulatePointToPointCollisions() {
if (p2pCols) {
super.simulatePointToPointCollisions();
}
}
};
} else {
simulator = new PointGameSimulator() {
final int nPoints = n;
final Point2D[] points = new Point2D[nPoints];
{
for (int i = 0; i < nPoints; i++) {
points[i] = new Point2DImpl();
}
}
@Override
int getNumPoints() {
return nPoints;
}
@Override
Point2D getPoint(int index) {
return points[index];
}
@Override
void simulatePointToPointCollisions() {
if (p2pCols) {
super.simulatePointToPointCollisions();
}
}
};
}
simulator.init();
}
@TearDown(Level.Trial)
public void tearDown() {
System.out.println("Point collisions: " + simulator.pointCollisions);
System.out.println("Wall collisions: " + simulator.wallCollisions);
}
@Benchmark
public void simulate() {
simulator.simulate();
}
static class Point2DImpl implements PointGameSimulator.Point2D {
float x, y, vx, vy;
// default constructor
public Point2DImpl() {
}
public Point2DImpl(float x, float y, float vx, float vy) {
this.x = x;
this.y = y;
this.vx = vx;
this.vy = vy;
}
@Override
public float getX() {
return x;
}
@Override
public void setX(float x) {
this.x = x;
}
@Override
public float getY() {
return y;
}
@Override
public void setY(float y) {
this.y = y;
}
@Override
public float getVx() {
return vx;
}
@Override
public void setVx(float vx) {
this.vx = vx;
}
@Override
public float getVy() {
return vy;
}
@Override
public void setVy(float vy) {
this.vy = vy;
}
@Override
public PointGameSimulator.Point2D copy() {
return new Point2DImpl(x, y, vx, vy);
}
}
}