use of com.graphhopper.util.MiniPerfTest in project graphhopper by graphhopper.
the class TrafficChangeWithNodeOrderingReusingTest method runPerformanceTest.
private static void runPerformanceTest(final GraphHopperStorage ghStorage, CHConfig chConfig, long seed, final int iterations) {
final int numNodes = ghStorage.getNodes();
RoutingCHGraph chGraph = ghStorage.createCHGraph(ghStorage.createCHStorage(chConfig), chConfig);
final Random random = new Random(seed);
LOGGER.info("Running performance test, seed = {}", seed);
final double[] distAndWeight = { 0.0, 0.0 };
MiniPerfTest performanceTest = new MiniPerfTest();
performanceTest.setIterations(iterations).start(new MiniPerfTest.Task() {
private long queryTime;
@Override
public int doCalc(boolean warmup, int run) {
if (!warmup && run % 1000 == 0) {
LOGGER.debug("Finished {} of {} runs. {}", run, iterations, run > 0 ? String.format(Locale.ROOT, " Time: %6.2fms", queryTime * 1.e-6 / run) : "");
}
if (run == iterations - 1) {
String avg = fmt(queryTime * 1.e-6 / run);
LOGGER.debug("Finished all ({}) runs, avg time: {}ms", iterations, avg);
}
int from = random.nextInt(numNodes);
int to = random.nextInt(numNodes);
long start = nanoTime();
RoutingAlgorithm algo = new CHRoutingAlgorithmFactory(chGraph).createAlgo(new PMap());
Path path = algo.calcPath(from, to);
if (!warmup && !path.isFound())
return 1;
if (!warmup) {
queryTime += nanoTime() - start;
double distance = path.getDistance();
double weight = path.getWeight();
distAndWeight[0] += distance;
distAndWeight[1] += weight;
}
return 0;
}
});
if (performanceTest.getDummySum() > 0.5 * iterations) {
throw new IllegalStateException("too many errors, probably something is wrong");
}
LOGGER.info("Total distance: {}, total weight: {}", distAndWeight[0], distAndWeight[1]);
LOGGER.info("Average query time: {}ms", performanceTest.getMean());
}
use of com.graphhopper.util.MiniPerfTest in project graphhopper by graphhopper.
the class CHImportTest method runQueries.
private static void runQueries(GraphHopper hopper, String profile) {
// Bavaria, but trying to avoid regions that are not covered
BBox bounds = new BBox(10.508422, 12.326602, 47.713457, 49.940615);
int numQueries = 10_000;
long seed = 123;
Random rnd = new Random(seed);
AtomicInteger notFoundCount = new AtomicInteger();
MiniPerfTest test = new MiniPerfTest().setIterations(numQueries).start((warmup, run) -> {
GHPoint from = getRandomPoint(rnd, bounds);
GHPoint to = getRandomPoint(rnd, bounds);
GHRequest req = new GHRequest(from, to).setProfile(profile);
GHResponse rsp = hopper.route(req);
if (rsp.hasErrors()) {
if (rsp.getErrors().stream().anyMatch(t -> !(t instanceof PointNotFoundException || t instanceof ConnectionNotFoundException)))
throw new IllegalStateException("Unexpected error: " + rsp.getErrors().toString());
notFoundCount.incrementAndGet();
return 0;
} else {
return (int) rsp.getBest().getRouteWeight();
}
});
System.out.println("Total queries: " + numQueries + ", Failed queries: " + notFoundCount.get());
System.out.println(test.getReport());
}
Aggregations