-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLightingBenchmark.java
More file actions
82 lines (67 loc) · 2.35 KB
/
LightingBenchmark.java
File metadata and controls
82 lines (67 loc) · 2.35 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
package com.aivean.raycasting2d;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.VerboseMode;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@Warmup(iterations = 8, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 8, time = 2, timeUnit = TimeUnit.SECONDS)
@Fork(value = 1,
jvmArgs = {"-Xms2048m", "-XX:+UseSuperWord"}
)
@State(Scope.Thread)
public class LightingBenchmark {
@Param({/*"80", */"100"})
int size;
int[][] inputFullyFilled;
int[][] inputSingleLight;
int[][] objectsQuarterFilled;
Lighting l;
@Setup
public void setup() {
inputFullyFilled = new int[size][size];
inputSingleLight = new int[size][size];
objectsQuarterFilled = new int[size][size];
for (int x = 0; x < size; x++) {
Arrays.fill(inputFullyFilled[x], 1);
}
inputSingleLight[size / 2][size / 2] = 1;
l = new Lighting(size);
for (int x = 0; x < size; x++) {
for (int y = 0; y < size; y++) {
if (x < size / 2 && y < size / 2)
objectsQuarterFilled[x][y] = 1;
}
}
}
@Benchmark
public void testLightingFullyFilled() {
l.setInputRotated(inputFullyFilled, Rotation.NO);
l.recalculateLighting(1F);
}
@Benchmark
public void testLightingSingleLightSource() {
l.setInputRotated(inputSingleLight, Rotation.NO);
l.recalculateLighting(1F);
}
@Benchmark
public void testLightingLightQuarterFilled() {
l.setInputRotated(objectsQuarterFilled, Rotation.NO);
l.recalculateLighting(1F);
}
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(".*" + LightingBenchmark.class.getSimpleName() + ".*")
.forks(1)
.verbosity(VerboseMode.EXTRA) //VERBOSE OUTPUT
// .addProfiler(LinuxPerfAsmProfiler.class)
// .addProfiler(LinuxPerfNormProfiler.class)
.build();
new Runner(opt).run();
}
}