Skip to content

Instantly share code, notes, and snippets.

@Jikoo
Created June 15, 2024 15:43
Show Gist options
  • Save Jikoo/276b092f597b2818ef20fe45476e4794 to your computer and use it in GitHub Desktop.
Save Jikoo/276b092f597b2818ef20fe45476e4794 to your computer and use it in GitHub Desktop.
GP PRTree Benchmarking
Benchmark (branchFactor) (claims) Mode Cnt Score Error Units
PRTreeSettingsBenchmark.query 15 250 avgt 3 0.054 ± 0.003 ms/op
PRTreeSettingsBenchmark.query 20 250 avgt 3 0.055 ± 0.012 ms/op
PRTreeSettingsBenchmark.query 25 250 avgt 3 0.053 ± 0.002 ms/op
PRTreeSettingsBenchmark.query 30 250 avgt 3 0.053 ± 0.007 ms/op
PRTreeSettingsBenchmark.query 35 250 avgt 3 0.053 ± 0.006 ms/op
PRTreeSettingsBenchmark.query 40 250 avgt 3 0.055 ± 0.006 ms/op
PRTreeSettingsBenchmark.query 45 250 avgt 3 0.058 ± 0.009 ms/op
PRTreeSettingsBenchmark.query 15 500 avgt 3 0.165 ± 0.006 ms/op
PRTreeSettingsBenchmark.query 20 500 avgt 3 0.165 ± 0.019 ms/op
PRTreeSettingsBenchmark.query 25 500 avgt 3 0.144 ± 0.016 ms/op
PRTreeSettingsBenchmark.query 30 500 avgt 3 0.146 ± 0.010 ms/op
PRTreeSettingsBenchmark.query 35 500 avgt 3 0.142 ± 0.014 ms/op
PRTreeSettingsBenchmark.query 40 500 avgt 3 0.157 ± 0.014 ms/op
PRTreeSettingsBenchmark.query 45 500 avgt 3 0.151 ± 0.052 ms/op
PRTreeSettingsBenchmark.query 15 750 avgt 3 0.332 ± 0.045 ms/op
PRTreeSettingsBenchmark.query 20 750 avgt 3 0.296 ± 0.041 ms/op
PRTreeSettingsBenchmark.query 25 750 avgt 3 0.293 ± 0.024 ms/op
PRTreeSettingsBenchmark.query 30 750 avgt 3 0.281 ± 0.094 ms/op
PRTreeSettingsBenchmark.query 35 750 avgt 3 0.273 ± 0.031 ms/op
PRTreeSettingsBenchmark.query 40 750 avgt 3 0.265 ± 0.016 ms/op
PRTreeSettingsBenchmark.query 45 750 avgt 3 0.269 ± 0.047 ms/op
PRTreeSettingsBenchmark.query 15 1000 avgt 3 0.533 ± 0.078 ms/op
PRTreeSettingsBenchmark.query 20 1000 avgt 3 0.461 ± 0.108 ms/op
PRTreeSettingsBenchmark.query 25 1000 avgt 3 0.417 ± 0.037 ms/op
PRTreeSettingsBenchmark.query 30 1000 avgt 3 0.422 ± 0.023 ms/op
PRTreeSettingsBenchmark.query 35 1000 avgt 3 0.461 ± 0.043 ms/op
PRTreeSettingsBenchmark.query 40 1000 avgt 3 0.394 ± 0.047 ms/op
PRTreeSettingsBenchmark.query 45 1000 avgt 3 0.386 ± 0.012 ms/op
PRTreeSettingsBenchmark.query 15 1250 avgt 3 0.685 ± 0.037 ms/op
PRTreeSettingsBenchmark.query 20 1250 avgt 3 0.657 ± 0.044 ms/op
PRTreeSettingsBenchmark.query 25 1250 avgt 3 0.568 ± 0.176 ms/op
PRTreeSettingsBenchmark.query 30 1250 avgt 3 0.524 ± 0.043 ms/op
PRTreeSettingsBenchmark.query 35 1250 avgt 3 0.544 ± 0.079 ms/op
PRTreeSettingsBenchmark.query 40 1250 avgt 3 0.542 ± 0.048 ms/op
PRTreeSettingsBenchmark.query 45 1250 avgt 3 0.528 ± 0.073 ms/op
PRTreeSettingsBenchmark.query 15 1500 avgt 3 0.923 ± 0.031 ms/op
PRTreeSettingsBenchmark.query 20 1500 avgt 3 0.793 ± 0.038 ms/op
PRTreeSettingsBenchmark.query 25 1500 avgt 3 0.734 ± 0.015 ms/op
PRTreeSettingsBenchmark.query 30 1500 avgt 3 0.672 ± 0.031 ms/op
PRTreeSettingsBenchmark.query 35 1500 avgt 3 0.677 ± 0.021 ms/op
PRTreeSettingsBenchmark.query 40 1500 avgt 3 0.727 ± 0.027 ms/op
PRTreeSettingsBenchmark.query 45 1500 avgt 3 0.646 ± 0.007 ms/op
PRTreeSettingsBenchmark.query 15 1750 avgt 3 1.073 ± 0.062 ms/op
PRTreeSettingsBenchmark.query 20 1750 avgt 3 0.977 ± 0.023 ms/op
PRTreeSettingsBenchmark.query 25 1750 avgt 3 0.989 ± 0.038 ms/op
PRTreeSettingsBenchmark.query 30 1750 avgt 3 0.901 ± 0.015 ms/op
PRTreeSettingsBenchmark.query 35 1750 avgt 3 0.884 ± 0.006 ms/op
PRTreeSettingsBenchmark.query 40 1750 avgt 3 0.899 ± 0.025 ms/op
PRTreeSettingsBenchmark.query 45 1750 avgt 3 0.949 ± 0.010 ms/op
PRTreeSettingsBenchmark.query 15 2000 avgt 3 1.368 ± 0.029 ms/op
PRTreeSettingsBenchmark.query 20 2000 avgt 3 1.227 ± 0.031 ms/op
PRTreeSettingsBenchmark.query 25 2000 avgt 3 1.196 ± 0.025 ms/op
PRTreeSettingsBenchmark.query 30 2000 avgt 3 1.112 ± 0.014 ms/op
PRTreeSettingsBenchmark.query 35 2000 avgt 3 0.998 ± 0.025 ms/op
PRTreeSettingsBenchmark.query 40 2000 avgt 3 1.048 ± 0.006 ms/op
PRTreeSettingsBenchmark.query 45 2000 avgt 3 1.160 ± 0.014 ms/op
PRTreeSettingsBenchmark.query 15 2250 avgt 3 1.434 ± 0.028 ms/op
PRTreeSettingsBenchmark.query 20 2250 avgt 3 1.567 ± 0.032 ms/op
PRTreeSettingsBenchmark.query 25 2250 avgt 3 1.368 ± 0.021 ms/op
PRTreeSettingsBenchmark.query 30 2250 avgt 3 1.295 ± 0.011 ms/op
PRTreeSettingsBenchmark.query 35 2250 avgt 3 1.375 ± 0.022 ms/op
PRTreeSettingsBenchmark.query 40 2250 avgt 3 1.257 ± 0.166 ms/op
PRTreeSettingsBenchmark.query 45 2250 avgt 3 1.299 ± 0.035 ms/op
PRTreeSettingsBenchmark.query 15 2500 avgt 3 1.944 ± 0.051 ms/op
PRTreeSettingsBenchmark.query 20 2500 avgt 3 1.692 ± 0.031 ms/op
PRTreeSettingsBenchmark.query 25 2500 avgt 3 1.719 ± 0.018 ms/op
PRTreeSettingsBenchmark.query 30 2500 avgt 3 1.558 ± 0.192 ms/op
PRTreeSettingsBenchmark.query 35 2500 avgt 3 1.518 ± 0.030 ms/op
PRTreeSettingsBenchmark.query 40 2500 avgt 3 1.666 ± 0.039 ms/op
PRTreeSettingsBenchmark.query 45 2500 avgt 3 1.448 ± 0.088 ms/op
PRTreeSettingsBenchmark.query 15 2750 avgt 3 2.245 ± 0.038 ms/op
PRTreeSettingsBenchmark.query 20 2750 avgt 3 2.046 ± 0.036 ms/op
PRTreeSettingsBenchmark.query 25 2750 avgt 3 1.801 ± 0.041 ms/op
PRTreeSettingsBenchmark.query 30 2750 avgt 3 1.883 ± 0.046 ms/op
PRTreeSettingsBenchmark.query 35 2750 avgt 3 1.816 ± 0.044 ms/op
PRTreeSettingsBenchmark.query 40 2750 avgt 3 1.602 ± 0.042 ms/op
PRTreeSettingsBenchmark.query 45 2750 avgt 3 1.812 ± 0.046 ms/op
PRTreeSettingsBenchmark.query 15 3000 avgt 3 2.562 ± 0.034 ms/op
PRTreeSettingsBenchmark.query 20 3000 avgt 3 2.212 ± 0.023 ms/op
PRTreeSettingsBenchmark.query 25 3000 avgt 3 2.049 ± 0.042 ms/op
PRTreeSettingsBenchmark.query 30 3000 avgt 3 1.973 ± 0.048 ms/op
PRTreeSettingsBenchmark.query 35 3000 avgt 3 1.929 ± 0.013 ms/op
PRTreeSettingsBenchmark.query 40 3000 avgt 3 2.002 ± 0.090 ms/op
PRTreeSettingsBenchmark.query 45 3000 avgt 3 1.767 ± 0.024 ms/op
PRTreeSettingsBenchmark.query 15 3250 avgt 3 2.617 ± 0.044 ms/op
PRTreeSettingsBenchmark.query 20 3250 avgt 3 2.621 ± 0.096 ms/op
PRTreeSettingsBenchmark.query 25 3250 avgt 3 2.539 ± 0.026 ms/op
PRTreeSettingsBenchmark.query 30 3250 avgt 3 2.360 ± 0.044 ms/op
PRTreeSettingsBenchmark.query 35 3250 avgt 3 2.494 ± 0.043 ms/op
PRTreeSettingsBenchmark.query 40 3250 avgt 3 2.192 ± 0.068 ms/op
PRTreeSettingsBenchmark.query 45 3250 avgt 3 2.110 ± 0.047 ms/op
PRTreeSettingsBenchmark.query 15 3500 avgt 3 2.906 ± 0.033 ms/op
PRTreeSettingsBenchmark.query 20 3500 avgt 3 2.719 ± 0.012 ms/op
PRTreeSettingsBenchmark.query 25 3500 avgt 3 2.627 ± 0.071 ms/op
PRTreeSettingsBenchmark.query 30 3500 avgt 3 2.695 ± 0.027 ms/op
PRTreeSettingsBenchmark.query 35 3500 avgt 3 2.619 ± 0.264 ms/op
PRTreeSettingsBenchmark.query 40 3500 avgt 3 2.394 ± 0.059 ms/op
PRTreeSettingsBenchmark.query 45 3500 avgt 3 2.279 ± 0.062 ms/op
PRTreeSettingsBenchmark.query 15 3750 avgt 3 3.149 ± 0.041 ms/op
PRTreeSettingsBenchmark.query 20 3750 avgt 3 3.105 ± 0.080 ms/op
PRTreeSettingsBenchmark.query 25 3750 avgt 3 2.954 ± 0.015 ms/op
PRTreeSettingsBenchmark.query 30 3750 avgt 3 3.115 ± 0.080 ms/op
PRTreeSettingsBenchmark.query 35 3750 avgt 3 2.892 ± 0.050 ms/op
PRTreeSettingsBenchmark.query 40 3750 avgt 3 2.733 ± 0.045 ms/op
PRTreeSettingsBenchmark.query 45 3750 avgt 3 2.775 ± 0.038 ms/op
PRTreeSettingsBenchmark.query 15 4000 avgt 3 3.830 ± 0.108 ms/op
PRTreeSettingsBenchmark.query 20 4000 avgt 3 3.339 ± 0.080 ms/op
PRTreeSettingsBenchmark.query 25 4000 avgt 3 3.028 ± 0.029 ms/op
PRTreeSettingsBenchmark.query 30 4000 avgt 3 3.009 ± 0.109 ms/op
PRTreeSettingsBenchmark.query 35 4000 avgt 3 3.250 ± 0.017 ms/op
PRTreeSettingsBenchmark.query 40 4000 avgt 3 2.971 ± 0.025 ms/op
PRTreeSettingsBenchmark.query 45 4000 avgt 3 2.806 ± 0.030 ms/op
PRTreeSettingsBenchmark.query 15 4250 avgt 3 3.990 ± 0.107 ms/op
PRTreeSettingsBenchmark.query 20 4250 avgt 3 3.640 ± 0.020 ms/op
PRTreeSettingsBenchmark.query 25 4250 avgt 3 3.495 ± 0.139 ms/op
PRTreeSettingsBenchmark.query 30 4250 avgt 3 3.234 ± 0.057 ms/op
PRTreeSettingsBenchmark.query 35 4250 avgt 3 3.411 ± 0.094 ms/op
PRTreeSettingsBenchmark.query 40 4250 avgt 3 3.286 ± 0.983 ms/op
PRTreeSettingsBenchmark.query 45 4250 avgt 3 3.286 ± 0.134 ms/op
PRTreeSettingsBenchmark.query 15 4500 avgt 3 4.303 ± 0.052 ms/op
PRTreeSettingsBenchmark.query 20 4500 avgt 3 3.979 ± 0.339 ms/op
PRTreeSettingsBenchmark.query 25 4500 avgt 3 3.854 ± 0.169 ms/op
PRTreeSettingsBenchmark.query 30 4500 avgt 3 3.650 ± 0.417 ms/op
PRTreeSettingsBenchmark.query 35 4500 avgt 3 3.952 ± 0.170 ms/op
PRTreeSettingsBenchmark.query 40 4500 avgt 3 3.576 ± 0.070 ms/op
PRTreeSettingsBenchmark.query 45 4500 avgt 3 4.028 ± 0.203 ms/op
PRTreeSettingsBenchmark.query 15 4750 avgt 3 4.573 ± 0.159 ms/op
PRTreeSettingsBenchmark.query 20 4750 avgt 3 4.561 ± 0.354 ms/op
PRTreeSettingsBenchmark.query 25 4750 avgt 3 4.477 ± 0.526 ms/op
PRTreeSettingsBenchmark.query 30 4750 avgt 3 4.376 ± 0.430 ms/op
PRTreeSettingsBenchmark.query 35 4750 avgt 3 3.941 ± 0.361 ms/op
PRTreeSettingsBenchmark.query 40 4750 avgt 3 3.818 ± 0.206 ms/op
PRTreeSettingsBenchmark.query 45 4750 avgt 3 4.284 ± 0.889 ms/op
PRTreeSettingsBenchmark.query 15 5000 avgt 3 5.234 ± 1.021 ms/op
PRTreeSettingsBenchmark.query 20 5000 avgt 3 4.970 ± 0.243 ms/op
PRTreeSettingsBenchmark.query 25 5000 avgt 3 4.748 ± 0.684 ms/op
PRTreeSettingsBenchmark.query 30 5000 avgt 3 5.199 ± 0.528 ms/op
PRTreeSettingsBenchmark.query 35 5000 avgt 3 4.189 ± 0.224 ms/op
PRTreeSettingsBenchmark.query 40 5000 avgt 3 4.439 ± 0.201 ms/op
PRTreeSettingsBenchmark.query 45 5000 avgt 3 4.303 ± 0.267 ms/op
import org.khelekore.prtree.PRTree;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.results.RunResult;
import org.openjdk.jmh.results.format.ResultFormatFactory;
import org.openjdk.jmh.results.format.ResultFormatType;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.VerboseMode;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.concurrent.TimeUnit;
@State(Scope.Thread)
public class PRTreeSettingsBenchmark {
@Param({"250"})
public static int claims;
@Param({"15"})
static int branchFactor;
static Collection<SpatialData.Box2D> data;
public static void main(String[] args) throws Exception {
Collection<RunResult> results = new ArrayList<>();
for (int claims = 250; claims <= 5000; claims += 250) {
System.out.printf("[%1$tH:%1$tM:%1$tS] Claims: %2$s%n", System.currentTimeMillis(), claims);
for (int branchFactor = 15; branchFactor < 50; branchFactor += 5) {
System.out.printf("[%1$tH:%1$tM:%1$tS] Branch factor: %2$s%n", System.currentTimeMillis(), branchFactor);
Options opts = new OptionsBuilder()
.include(new Object() {}.getClass().getEnclosingClass().getSimpleName())
.param("claims", String.valueOf(claims))
.param("branchFactor", String.valueOf(branchFactor))
.forks(1)
.warmupIterations(2)
.measurementIterations(3)
.mode(Mode.AverageTime)
.timeUnit(TimeUnit.MILLISECONDS)
.verbosity(VerboseMode.SILENT)
.build();
Collection<RunResult> run = new Runner(opts).run();
ResultFormatFactory.getInstance(ResultFormatType.TEXT, System.out).writeOut(run);
results.addAll(run);
}
}
System.out.println("\n");
ResultFormatFactory.getInstance(ResultFormatType.TEXT, System.out).writeOut(results);
}
@Setup(Level.Trial)
public void setUp() {
data = SpatialData.getData(0, claims, 0);
}
@State(Scope.Benchmark)
public static class BaseState {
PRTree<SpatialData.Box2D> prTree;
Collection<SpatialData.Box2D> prTreeContent;
@Setup(Level.Trial)
public void setUp() {
data = SpatialData.getData(0, claims, 0);
PRTree<SpatialData.Box2D> temp = new PRTree<>(PRTreeBenchmark.BOX2D_MBR_CONVERTER, branchFactor);
temp.load(data);
prTreeContent = new HashSet<>(data);
prTree = temp;
}
}
@State(Scope.Benchmark)
public static class DeleteState extends BaseState {
@Setup(Level.Invocation)
public void setUp() {
super.setUp();
}
}
@Benchmark
@Measurement(batchSize = 1, iterations = 5)
public PRTree<SpatialData.Box2D> load(BaseState state) {
PRTree<SpatialData.Box2D> temp = new PRTree<>(PRTreeBenchmark.BOX2D_MBR_CONVERTER, branchFactor);
temp.load(data);
state.prTreeContent = new HashSet<>(data);
state.prTree = temp;
return state.prTree;
}
@Benchmark
@Measurement(batchSize = 1, iterations = 5)
public SpatialData.Box2D query(BaseState state) {
SpatialData.Box2D value = null;
for (SpatialData.Box2D box : data) {
for (SpatialData.Box2D found : state.prTree.find(box.min1(), box.min2(), box.max1(), box.max2())) {
value = found;
}
}
return value;
}
@Benchmark
@Measurement(batchSize = 1, iterations = 5)
public PRTree<SpatialData.Box2D> bulkDelete(DeleteState state) {
state.prTreeContent.removeAll(data);
state.prTree = new PRTree<>(PRTreeBenchmark.BOX2D_MBR_CONVERTER, branchFactor);
state.prTree.load(state.prTreeContent);
return state.prTree;
}
}
import java.util.ArrayList;
import java.util.Collection;
import java.util.Random;
public class SpatialData {
public record Box2D(int min1, int min2, int max1, int max2) {}
public static Collection<Box2D> getData(long seed, int small, int big) {
int min = -30_000_000;
int max = 30_000_000;
Random random = new Random(seed); // seeded for consistent pseudo-rng
Collection<Box2D> data = new ArrayList<>(small + big);
// normal
for (int i = 0; i < small; ++i) {
data.add(rectangle(random, min, max, 10, 100));
}
// huge
for (int i = 0; i < big; ++i) {
data.add(rectangle(random, min, max, 1_000, 100_000));
}
return data;
}
private static Box2D rectangle(Random random, int min, int max, int rangeMin, int rangeMax) {
int start1 = random.nextInt(min, max);
int start2 = random.nextInt(min, max);
int end1 = start1 + random.nextInt(rangeMin, rangeMax); // technically can exceed max but who really cares
int end2 = start2 + random.nextInt(rangeMin, rangeMax);
return new Box2D(start1, start2, end1, end2);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment