Skip to content

Commit

Permalink
add pmtiles serialization/deserialization benchmark [onthegomap#98]
Browse files Browse the repository at this point in the history
  • Loading branch information
bdon committed Feb 1, 2023
1 parent 21247da commit 3500732
Showing 1 changed file with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<Pmtiles.Entry>();

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)"
);
}
}
}

0 comments on commit 3500732

Please sign in to comment.