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

Function runNearestBenchmark

src/benchmarks/bench.cpp:440–490  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

438}
439
440void runNearestBenchmark(const OSRM &osrm, const GPSTraces &gpsTraces, int iterations)
441{
442 struct Benchmark
443 {
444 std::string name;
445 std::optional<size_t> number_of_results = std::nullopt;
446 };
447
448 std::vector<Benchmark> benchmarks = {{"10000 nearest, number_of_results=1", 1},
449 {"10000 nearest, number_of_results=5", 5},
450 {"10000 nearest, number_of_results=10", 10}};
451
452 runBenchmarks(benchmarks,
453 iterations,
454 10000,
455 osrm,
456 gpsTraces,
457 [](int iteration,
458 const Benchmark &benchmark,
459 const OSRM &osrm,
460 const GPSTraces &gpsTraces,
461 Statistics &statistics)
462 {
463 engine::api::ResultT result = json::Object();
464 NearestParameters params;
465 params.coordinates.push_back(gpsTraces.getRandomCoordinate());
466
467 if (benchmark.number_of_results)
468 {
469 params.number_of_results = *benchmark.number_of_results;
470 }
471
472 TIMER_START(nearest);
473 const auto rc = osrm.Nearest(params, result);
474 TIMER_STOP(nearest);
475
476 auto &json_result = std::get<json::Object>(result);
477 if (rc != Status::Ok || !json_result.values.contains("waypoints"))
478 {
479 auto code = std::get<json::String>(json_result.values["code"]).value;
480 if (code != "NoSegment")
481 {
482 throw std::runtime_error{"Couldn't find nearest point"};
483 }
484 }
485 else
486 {
487 statistics.push(TIMER_MSEC(nearest), iteration);
488 }
489 });
490}
491
492void runTripBenchmark(const OSRM &osrm, const GPSTraces &gpsTraces, int iterations)
493{

Callers 1

mainFunction · 0.85

Calls 7

runBenchmarksFunction · 0.85
getRandomCoordinateMethod · 0.80
containsMethod · 0.80
pushMethod · 0.80
ObjectClass · 0.50
push_backMethod · 0.45
NearestMethod · 0.45

Tested by

no test coverage detected