|
| 1 | +#include "engine/engine_config.hpp" |
| 2 | +#include "util/coordinate.hpp" |
| 3 | +#include "util/timing_util.hpp" |
| 4 | + |
| 5 | +#include "osrm/route_parameters.hpp" |
| 6 | + |
| 7 | +#include "osrm/coordinate.hpp" |
| 8 | +#include "osrm/engine_config.hpp" |
| 9 | +#include "osrm/json_container.hpp" |
| 10 | + |
| 11 | +#include "osrm/osrm.hpp" |
| 12 | +#include "osrm/status.hpp" |
| 13 | + |
| 14 | +#include <boost/assert.hpp> |
| 15 | + |
| 16 | +#include <boost/optional/optional.hpp> |
| 17 | +#include <cstdlib> |
| 18 | +#include <exception> |
| 19 | +#include <iostream> |
| 20 | +#include <optional> |
| 21 | +#include <stdexcept> |
| 22 | +#include <string> |
| 23 | +#include <vector> |
| 24 | + |
| 25 | +int main(int argc, const char *argv[]) |
| 26 | +try |
| 27 | +{ |
| 28 | + if (argc < 2) |
| 29 | + { |
| 30 | + std::cerr << "Usage: " << argv[0] << " data.osrm\n"; |
| 31 | + return EXIT_FAILURE; |
| 32 | + } |
| 33 | + |
| 34 | + using namespace osrm; |
| 35 | + |
| 36 | + // Configure based on a .osrm base path, and no datasets in shared mem from osrm-datastore |
| 37 | + EngineConfig config; |
| 38 | + config.storage_config = {argv[1]}; |
| 39 | + config.algorithm = (argc > 2 && std::string{argv[2]} == "mld") ? EngineConfig::Algorithm::MLD |
| 40 | + : EngineConfig::Algorithm::CH; |
| 41 | + config.use_shared_memory = false; |
| 42 | + |
| 43 | + // Routing machine with several services (such as Route, Table, Nearest, Trip, Match) |
| 44 | + OSRM osrm{config}; |
| 45 | + |
| 46 | + struct Benchmark |
| 47 | + { |
| 48 | + std::string name; |
| 49 | + std::vector<util::Coordinate> coordinates; |
| 50 | + RouteParameters::OverviewType overview; |
| 51 | + bool steps = false; |
| 52 | + std::optional<size_t> alternatives = std::nullopt; |
| 53 | + std::optional<double> radius = std::nullopt; |
| 54 | + }; |
| 55 | + |
| 56 | + auto run_benchmark = [&](const Benchmark &benchmark) |
| 57 | + { |
| 58 | + RouteParameters params; |
| 59 | + params.overview = benchmark.overview; |
| 60 | + params.steps = benchmark.steps; |
| 61 | + params.coordinates = benchmark.coordinates; |
| 62 | + if (benchmark.alternatives) |
| 63 | + { |
| 64 | + params.alternatives = *benchmark.alternatives; |
| 65 | + } |
| 66 | + |
| 67 | + if (benchmark.radius) |
| 68 | + { |
| 69 | + params.radiuses = std::vector<boost::optional<double>>( |
| 70 | + params.coordinates.size(), boost::make_optional(*benchmark.radius)); |
| 71 | + } |
| 72 | + |
| 73 | + TIMER_START(routes); |
| 74 | + auto NUM = 1000; |
| 75 | + for (int i = 0; i < NUM; ++i) |
| 76 | + { |
| 77 | + engine::api::ResultT result = json::Object(); |
| 78 | + const auto rc = osrm.Route(params, result); |
| 79 | + auto &json_result = result.get<json::Object>(); |
| 80 | + if (rc != Status::Ok || json_result.values.find("routes") == json_result.values.end()) |
| 81 | + { |
| 82 | + throw std::runtime_error{"Couldn't route"}; |
| 83 | + } |
| 84 | + } |
| 85 | + TIMER_STOP(routes); |
| 86 | + std::cout << benchmark.name << std::endl; |
| 87 | + std::cout << TIMER_MSEC(routes) << "ms" << std::endl; |
| 88 | + std::cout << TIMER_MSEC(routes) / NUM << "ms/req" << std::endl; |
| 89 | + }; |
| 90 | + |
| 91 | + std::vector<Benchmark> benchmarks = { |
| 92 | + {"1000 routes, 3 coordinates, no alternatives, overview=full, steps=true", |
| 93 | + {{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}}, |
| 94 | + {FloatLongitude{7.421844922513342}, FloatLatitude{43.73690777888953}}, |
| 95 | + {FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}}, |
| 96 | + RouteParameters::OverviewType::Full, |
| 97 | + true, |
| 98 | + std::nullopt}, |
| 99 | + {"1000 routes, 2 coordinates, no alternatives, overview=full, steps=true", |
| 100 | + {{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}}, |
| 101 | + {FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}}, |
| 102 | + RouteParameters::OverviewType::Full, |
| 103 | + true, |
| 104 | + std::nullopt}, |
| 105 | + {"1000 routes, 2 coordinates, 3 alternatives, overview=full, steps=true", |
| 106 | + {{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}}, |
| 107 | + {FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}}, |
| 108 | + RouteParameters::OverviewType::Full, |
| 109 | + true, |
| 110 | + 3}, |
| 111 | + {"1000 routes, 3 coordinates, no alternatives, overview=false, steps=false", |
| 112 | + {{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}}, |
| 113 | + {FloatLongitude{7.421844922513342}, FloatLatitude{43.73690777888953}}, |
| 114 | + {FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}}, |
| 115 | + RouteParameters::OverviewType::False, |
| 116 | + false, |
| 117 | + std::nullopt}, |
| 118 | + {"1000 routes, 2 coordinates, no alternatives, overview=false, steps=false", |
| 119 | + {{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}}, |
| 120 | + {FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}}, |
| 121 | + RouteParameters::OverviewType::False, |
| 122 | + false, |
| 123 | + std::nullopt}, |
| 124 | + {"1000 routes, 2 coordinates, 3 alternatives, overview=false, steps=false", |
| 125 | + {{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}}, |
| 126 | + {FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}}, |
| 127 | + RouteParameters::OverviewType::False, |
| 128 | + false, |
| 129 | + 3}, |
| 130 | + {"1000 routes, 3 coordinates, no alternatives, overview=false, steps=false, radius=750", |
| 131 | + {{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}}, |
| 132 | + {FloatLongitude{7.421844922513342}, FloatLatitude{43.73690777888953}}, |
| 133 | + {FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}}, |
| 134 | + RouteParameters::OverviewType::False, |
| 135 | + false, |
| 136 | + std::nullopt, |
| 137 | + 750}, |
| 138 | + {"1000 routes, 2 coordinates, no alternatives, overview=false, steps=false, radius=750", |
| 139 | + {{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}}, |
| 140 | + {FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}}, |
| 141 | + RouteParameters::OverviewType::False, |
| 142 | + false, |
| 143 | + std::nullopt, |
| 144 | + 750}, |
| 145 | + {"1000 routes, 2 coordinates, 3 alternatives, overview=false, steps=false, radius=750", |
| 146 | + {{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}}, |
| 147 | + {FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}}, |
| 148 | + RouteParameters::OverviewType::False, |
| 149 | + false, |
| 150 | + 3, |
| 151 | + 750} |
| 152 | + |
| 153 | + }; |
| 154 | + |
| 155 | + for (const auto &benchmark : benchmarks) |
| 156 | + { |
| 157 | + run_benchmark(benchmark); |
| 158 | + } |
| 159 | + |
| 160 | + return EXIT_SUCCESS; |
| 161 | +} |
| 162 | +catch (const std::exception &e) |
| 163 | +{ |
| 164 | + std::cerr << "Error: " << e.what() << std::endl; |
| 165 | + return EXIT_FAILURE; |
| 166 | +} |
0 commit comments