| 438 | } |
| 439 | |
| 440 | void 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 | |
| 492 | void runTripBenchmark(const OSRM &osrm, const GPSTraces &gpsTraces, int iterations) |
| 493 | { |
no test coverage detected