2021-12-23 10:42:24 +00:00
|
|
|
package com.onthegomap.planetiler.benchmarks;
|
2021-08-17 10:25:30 +00:00
|
|
|
|
2021-12-23 10:42:24 +00:00
|
|
|
import com.onthegomap.planetiler.basemap.BasemapProfile;
|
|
|
|
import com.onthegomap.planetiler.config.PlanetilerConfig;
|
|
|
|
import com.onthegomap.planetiler.expression.MultiExpression;
|
|
|
|
import com.onthegomap.planetiler.reader.SourceFeature;
|
2022-03-01 01:52:30 +00:00
|
|
|
import com.onthegomap.planetiler.reader.osm.OsmElement;
|
2021-12-23 10:42:24 +00:00
|
|
|
import com.onthegomap.planetiler.reader.osm.OsmInputFile;
|
2022-03-01 01:52:30 +00:00
|
|
|
import com.onthegomap.planetiler.stats.ProgressLoggers;
|
2021-12-23 10:42:24 +00:00
|
|
|
import com.onthegomap.planetiler.stats.Stats;
|
|
|
|
import com.onthegomap.planetiler.util.Translations;
|
2021-08-17 10:25:30 +00:00
|
|
|
import java.nio.file.Path;
|
|
|
|
import java.time.Duration;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Random;
|
|
|
|
import org.locationtech.jts.geom.Geometry;
|
|
|
|
|
2021-09-10 00:46:20 +00:00
|
|
|
/**
|
2022-03-09 02:08:03 +00:00
|
|
|
* Performance tests for {@link MultiExpression}. Times how long a sample of elements from an OSM input file take to
|
2021-09-10 00:46:20 +00:00
|
|
|
* match.
|
|
|
|
*/
|
2021-10-20 01:57:47 +00:00
|
|
|
public class BasemapMapping {
|
2021-08-17 10:25:30 +00:00
|
|
|
|
2022-03-01 01:52:30 +00:00
|
|
|
public static void main(String[] args) throws Exception {
|
2021-12-23 10:42:24 +00:00
|
|
|
var profile = new BasemapProfile(Translations.nullProvider(List.of()), PlanetilerConfig.defaults(),
|
2021-09-10 00:46:20 +00:00
|
|
|
Stats.inMemory());
|
2021-08-17 10:25:30 +00:00
|
|
|
var random = new Random(0);
|
|
|
|
List<SourceFeature> inputs = new ArrayList<>();
|
2022-03-01 01:52:30 +00:00
|
|
|
var logger = ProgressLoggers.create()
|
|
|
|
.addRateCounter("inputs", inputs::size)
|
|
|
|
.addProcessStats();
|
|
|
|
try (var reader = OsmInputFile.readFrom(Path.of("data", "sources", "massachusetts.osm.pbf"))) {
|
|
|
|
reader.forEachBlock(block -> {
|
|
|
|
for (var element : block.decodeElements()) {
|
|
|
|
if (random.nextDouble() < 0.2) {
|
|
|
|
if (inputs.size() % 1_000_000 == 0) {
|
|
|
|
logger.log();
|
|
|
|
}
|
|
|
|
inputs.add(new SourceFeature(element.tags(), "", "", null, element.id()) {
|
|
|
|
@Override
|
|
|
|
public Geometry latLonGeometry() {
|
|
|
|
return null;
|
|
|
|
}
|
2021-08-17 10:25:30 +00:00
|
|
|
|
2022-03-01 01:52:30 +00:00
|
|
|
@Override
|
|
|
|
public Geometry worldGeometry() {
|
|
|
|
return null;
|
|
|
|
}
|
2021-08-17 10:25:30 +00:00
|
|
|
|
2022-03-01 01:52:30 +00:00
|
|
|
@Override
|
|
|
|
public boolean isPoint() {
|
|
|
|
return element instanceof OsmElement.Node;
|
|
|
|
}
|
2021-08-17 10:25:30 +00:00
|
|
|
|
2022-03-01 01:52:30 +00:00
|
|
|
@Override
|
|
|
|
public boolean canBePolygon() {
|
|
|
|
return element instanceof OsmElement.Way || element instanceof OsmElement.Relation;
|
|
|
|
}
|
2021-08-17 10:25:30 +00:00
|
|
|
|
2022-03-01 01:52:30 +00:00
|
|
|
@Override
|
|
|
|
public boolean canBeLine() {
|
|
|
|
return element instanceof OsmElement.Way;
|
|
|
|
}
|
|
|
|
});
|
2021-08-17 10:25:30 +00:00
|
|
|
}
|
2022-03-01 01:52:30 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2021-08-17 10:25:30 +00:00
|
|
|
|
2022-03-01 01:52:30 +00:00
|
|
|
logger.log();
|
2021-08-17 10:25:30 +00:00
|
|
|
System.err.println("read " + inputs.size() + " elems");
|
|
|
|
|
|
|
|
long startStart = System.nanoTime();
|
|
|
|
long count = -1;
|
|
|
|
while (true) {
|
|
|
|
count++;
|
|
|
|
long start = System.nanoTime();
|
|
|
|
int i = 0;
|
|
|
|
for (SourceFeature in : inputs) {
|
|
|
|
i += profile.getTableMatches(in).size();
|
|
|
|
}
|
|
|
|
if (count == 0) {
|
|
|
|
startStart = System.nanoTime();
|
2022-03-01 01:52:30 +00:00
|
|
|
logger.log();
|
2021-08-17 10:25:30 +00:00
|
|
|
System.err.println("finished warmup");
|
|
|
|
} else {
|
2022-03-01 01:52:30 +00:00
|
|
|
logger.log();
|
2021-08-17 10:25:30 +00:00
|
|
|
System.err.println(
|
|
|
|
"took:" + Duration.ofNanos(System.nanoTime() - start).toMillis() + "ms found:" + i + " avg:" + (Duration
|
|
|
|
.ofNanos(System.nanoTime() - startStart).toMillis() / count) + "ms");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|