diff --git a/planetiler-benchmarks/src/main/java/com/onthegomap/planetiler/benchmarks/BenchmarkPmtiles.java b/planetiler-benchmarks/src/main/java/com/onthegomap/planetiler/benchmarks/BenchmarkPmtiles.java new file mode 100644 index 0000000000..3ae8a4e20f --- /dev/null +++ b/planetiler-benchmarks/src/main/java/com/onthegomap/planetiler/benchmarks/BenchmarkPmtiles.java @@ -0,0 +1,45 @@ +package com.onthegomap.planetiler.benchmarks; + +import static io.prometheus.client.Collector.NANOSECONDS_PER_SECOND; + +import com.carrotsearch.hppc.ObjectArrayList; +import com.onthegomap.planetiler.pmtiles.Pmtiles; +import com.onthegomap.planetiler.stats.Timer; +import com.onthegomap.planetiler.util.Format; +import java.io.IOException; +import java.util.Random; + +public class BenchmarkPmtiles { + + public static void main(String[] args) throws IOException { + + long num = 40_000_000; + + var random = new Random(0); + + for (int i = 0; i < 3; i++) { + + var entries = new ObjectArrayList(); + + long offset = 0; + for (int j = 0; j < num; j++) { + int len = random.nextInt(200, 64000); + entries.add(new Pmtiles.Entry(j, offset, len, 1)); + offset += len; + } + + var timer = Timer.start(); + + var result = Pmtiles.deserializeDirectory(Pmtiles.serializeDirectory(entries, 0, entries.size())); + assert (result.size() == entries.size()); + + System.err.println( + num + " entries took " + + Format.defaultInstance().duration(timer.stop().elapsed().wall()) + " (" + + Format.defaultInstance() + .numeric(num * 1d / (timer.stop().elapsed().wall().toNanos() / NANOSECONDS_PER_SECOND)) + + "/s)" + ); + } + } +}