Skip to content

Commit 73fb53c

Browse files
Add benchmark for route (#6890)
1 parent efe6840 commit 73fb53c

File tree

3 files changed

+182
-1
lines changed

3 files changed

+182
-1
lines changed

scripts/ci/run_benchmarks.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ function run_benchmarks_for_folder {
1313

1414
./$BENCHMARKS_FOLDER/match-bench "./$FOLDER/test/data/mld/monaco.osrm" mld > "$RESULTS_FOLDER/match_mld.bench"
1515
./$BENCHMARKS_FOLDER/match-bench "./$FOLDER/test/data/ch/monaco.osrm" ch > "$RESULTS_FOLDER/match_ch.bench"
16+
./$BENCHMARKS_FOLDER/route-bench "./$FOLDER/test/data/mld/monaco.osrm" mld > "$RESULTS_FOLDER/route_mld.bench" || true # TODO: remove `true` when this benchmark will be merged to master
17+
./$BENCHMARKS_FOLDER/route-bench "./$FOLDER/test/data/ch/monaco.osrm" ch > "$RESULTS_FOLDER/route_ch.bench" || true # TODO: remove `true` when this benchmark will be merged to master
1618
./$BENCHMARKS_FOLDER/alias-bench > "$RESULTS_FOLDER/alias.bench"
1719
./$BENCHMARKS_FOLDER/json-render-bench "./$FOLDER/src/benchmarks/portugal_to_korea.json" > "$RESULTS_FOLDER/json-render.bench"
1820
./$BENCHMARKS_FOLDER/packedvector-bench > "$RESULTS_FOLDER/packedvector.bench"

src/benchmarks/CMakeLists.txt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ target_link_libraries(match-bench
3030
${TBB_LIBRARIES}
3131
${MAYBE_SHAPEFILE})
3232

33+
add_executable(route-bench
34+
EXCLUDE_FROM_ALL
35+
route.cpp
36+
$<TARGET_OBJECTS:UTIL>)
37+
38+
target_link_libraries(route-bench
39+
osrm
40+
${BOOST_BASE_LIBRARIES}
41+
${CMAKE_THREAD_LIBS_INIT}
42+
${TBB_LIBRARIES}
43+
${MAYBE_SHAPEFILE})
44+
3345
add_executable(json-render-bench
3446
EXCLUDE_FROM_ALL
3547
json_render.cpp
@@ -72,5 +84,6 @@ add_custom_target(benchmarks
7284
rtree-bench
7385
packedvector-bench
7486
match-bench
87+
route-bench
7588
json-render-bench
76-
alias-bench)
89+
alias-bench)

src/benchmarks/route.cpp

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
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

Comments
 (0)