Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ tasks {
val compilerArgs = options.compilerArgs
options.encoding = Charsets.UTF_8.name()
compilerArgs.add("--add-modules=jdk.incubator.vector") // Gale - Pufferfish - SIMD support
compilerArgs.add("-Xlint:-deprecation")
compilerArgs.add("-Xlint:-unchecked")
compilerArgs.add("-Xlint:-removal")
}

build.configure {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/dreeam/sunbox/SunBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static void main(String[] args) {
private static void runJMH() throws Exception {
Options opt = new OptionsBuilder()
// TODO: Notice: Include benchmark class name you want
.include("NonNullListGetBenchmark")
.include("BiomeLookupBenchmark")
.forks(1)
.warmupIterations(4)
.measurementIterations(10)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package cn.dreeam.sunbox.benchmarks.jmh;

import org.openjdk.jmh.annotations.*;
import java.util.Random;
import java.util.concurrent.TimeUnit;

/*
Estimate running time: ~2mins
Target patch: Carpet-Fixes-Optimized-getBiome-method.patch
Target PR: https://github.com/Winds-Studio/Leaf/pull/637
*/
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@State(Scope.Thread)
public class BiomeLookupBenchmark {

private static final double[] QUART_OFFSETS = {0.0D, 0.25D, 0.5D, 0.75D};

private int[] inputData;
private static final int SIZE = 4096;

@Setup
public void setup() {
inputData = new int[SIZE];
Random rand = new Random(12345L);
for (int i = 0; i < SIZE; i++) {
inputData[i] = rand.nextInt();
}
}

@Benchmark
public double testFpDivision() {
double sum = 0;
for (int i = 0; i < SIZE; i++) {
sum += (double) (inputData[i] & 3) / 4.0;
}
return sum;
}

@Benchmark
public double testTableLookup() {
double sum = 0;
for (int i = 0; i < SIZE; i++) {
sum += QUART_OFFSETS[inputData[i] & 3];
}
return sum;
}
}