MCPcopy Create free account
hub / github.com/Project-OSRM/osrm-backend / runMatchBenchmark

Function runMatchBenchmark

src/benchmarks/bench.cpp:387–438  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

385}
386
387void runMatchBenchmark(const OSRM &osrm, const GPSTraces &gpsTraces, int iterations)
388{
389 struct Benchmark
390 {
391 std::string name;
392 std::optional<size_t> radius = std::nullopt;
393 };
394
395 std::vector<Benchmark> benchmarks = {{"500 matches, default radius"},
396 {"500 matches, radius=10", 10},
397 {"500 matches, radius=20", 20}};
398
399 runBenchmarks(benchmarks,
400 iterations,
401 500,
402 osrm,
403 gpsTraces,
404 [](int iteration,
405 const Benchmark &benchmark,
406 const OSRM &osrm,
407 const GPSTraces &gpsTraces,
408 Statistics &statistics)
409 {
410 engine::api::ResultT result = json::Object();
411
412 engine::api::MatchParameters params;
413 params.coordinates = gpsTraces.getRandomTrace();
414 if (benchmark.radius)
415 {
416 params.radiuses = std::vector<std::optional<double>>(
417 params.coordinates.size(), benchmark.radius);
418 }
419
420 TIMER_START(match);
421 const auto rc = osrm.Match(params, result);
422 TIMER_STOP(match);
423
424 auto &json_result = std::get<json::Object>(result);
425 if (rc != Status::Ok || !json_result.values.contains("matchings"))
426 {
427 auto code = std::get<json::String>(json_result.values["code"]).value;
428 if (code != "NoSegment" && code != "NoMatch")
429 {
430 throw std::runtime_error{"Couldn't route: " + code};
431 }
432 }
433 else
434 {
435 statistics.push(TIMER_MSEC(match), iteration);
436 }
437 });
438}
439
440void runNearestBenchmark(const OSRM &osrm, const GPSTraces &gpsTraces, int iterations)
441{

Callers 1

mainFunction · 0.85

Calls 7

runBenchmarksFunction · 0.85
getRandomTraceMethod · 0.80
containsMethod · 0.80
pushMethod · 0.80
ObjectClass · 0.50
sizeMethod · 0.45
MatchMethod · 0.45

Tested by

no test coverage detected