Add benchmark for route (#6890)
This commit is contained in:
parent
efe6840d08
commit
73fb53cf36
@ -13,6 +13,8 @@ function run_benchmarks_for_folder {
|
||||
|
||||
./$BENCHMARKS_FOLDER/match-bench "./$FOLDER/test/data/mld/monaco.osrm" mld > "$RESULTS_FOLDER/match_mld.bench"
|
||||
./$BENCHMARKS_FOLDER/match-bench "./$FOLDER/test/data/ch/monaco.osrm" ch > "$RESULTS_FOLDER/match_ch.bench"
|
||||
./$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
|
||||
./$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
|
||||
./$BENCHMARKS_FOLDER/alias-bench > "$RESULTS_FOLDER/alias.bench"
|
||||
./$BENCHMARKS_FOLDER/json-render-bench "./$FOLDER/src/benchmarks/portugal_to_korea.json" > "$RESULTS_FOLDER/json-render.bench"
|
||||
./$BENCHMARKS_FOLDER/packedvector-bench > "$RESULTS_FOLDER/packedvector.bench"
|
||||
|
@ -30,6 +30,18 @@ target_link_libraries(match-bench
|
||||
${TBB_LIBRARIES}
|
||||
${MAYBE_SHAPEFILE})
|
||||
|
||||
add_executable(route-bench
|
||||
EXCLUDE_FROM_ALL
|
||||
route.cpp
|
||||
$<TARGET_OBJECTS:UTIL>)
|
||||
|
||||
target_link_libraries(route-bench
|
||||
osrm
|
||||
${BOOST_BASE_LIBRARIES}
|
||||
${CMAKE_THREAD_LIBS_INIT}
|
||||
${TBB_LIBRARIES}
|
||||
${MAYBE_SHAPEFILE})
|
||||
|
||||
add_executable(json-render-bench
|
||||
EXCLUDE_FROM_ALL
|
||||
json_render.cpp
|
||||
@ -72,5 +84,6 @@ add_custom_target(benchmarks
|
||||
rtree-bench
|
||||
packedvector-bench
|
||||
match-bench
|
||||
route-bench
|
||||
json-render-bench
|
||||
alias-bench)
|
||||
|
166
src/benchmarks/route.cpp
Normal file
166
src/benchmarks/route.cpp
Normal file
@ -0,0 +1,166 @@
|
||||
#include "engine/engine_config.hpp"
|
||||
#include "util/coordinate.hpp"
|
||||
#include "util/timing_util.hpp"
|
||||
|
||||
#include "osrm/route_parameters.hpp"
|
||||
|
||||
#include "osrm/coordinate.hpp"
|
||||
#include "osrm/engine_config.hpp"
|
||||
#include "osrm/json_container.hpp"
|
||||
|
||||
#include "osrm/osrm.hpp"
|
||||
#include "osrm/status.hpp"
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
#include <boost/optional/optional.hpp>
|
||||
#include <cstdlib>
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
#include <optional>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
try
|
||||
{
|
||||
if (argc < 2)
|
||||
{
|
||||
std::cerr << "Usage: " << argv[0] << " data.osrm\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
using namespace osrm;
|
||||
|
||||
// Configure based on a .osrm base path, and no datasets in shared mem from osrm-datastore
|
||||
EngineConfig config;
|
||||
config.storage_config = {argv[1]};
|
||||
config.algorithm = (argc > 2 && std::string{argv[2]} == "mld") ? EngineConfig::Algorithm::MLD
|
||||
: EngineConfig::Algorithm::CH;
|
||||
config.use_shared_memory = false;
|
||||
|
||||
// Routing machine with several services (such as Route, Table, Nearest, Trip, Match)
|
||||
OSRM osrm{config};
|
||||
|
||||
struct Benchmark
|
||||
{
|
||||
std::string name;
|
||||
std::vector<util::Coordinate> coordinates;
|
||||
RouteParameters::OverviewType overview;
|
||||
bool steps = false;
|
||||
std::optional<size_t> alternatives = std::nullopt;
|
||||
std::optional<double> radius = std::nullopt;
|
||||
};
|
||||
|
||||
auto run_benchmark = [&](const Benchmark &benchmark)
|
||||
{
|
||||
RouteParameters params;
|
||||
params.overview = benchmark.overview;
|
||||
params.steps = benchmark.steps;
|
||||
params.coordinates = benchmark.coordinates;
|
||||
if (benchmark.alternatives)
|
||||
{
|
||||
params.alternatives = *benchmark.alternatives;
|
||||
}
|
||||
|
||||
if (benchmark.radius)
|
||||
{
|
||||
params.radiuses = std::vector<boost::optional<double>>(
|
||||
params.coordinates.size(), boost::make_optional(*benchmark.radius));
|
||||
}
|
||||
|
||||
TIMER_START(routes);
|
||||
auto NUM = 1000;
|
||||
for (int i = 0; i < NUM; ++i)
|
||||
{
|
||||
engine::api::ResultT result = json::Object();
|
||||
const auto rc = osrm.Route(params, result);
|
||||
auto &json_result = result.get<json::Object>();
|
||||
if (rc != Status::Ok || json_result.values.find("routes") == json_result.values.end())
|
||||
{
|
||||
throw std::runtime_error{"Couldn't route"};
|
||||
}
|
||||
}
|
||||
TIMER_STOP(routes);
|
||||
std::cout << benchmark.name << std::endl;
|
||||
std::cout << TIMER_MSEC(routes) << "ms" << std::endl;
|
||||
std::cout << TIMER_MSEC(routes) / NUM << "ms/req" << std::endl;
|
||||
};
|
||||
|
||||
std::vector<Benchmark> benchmarks = {
|
||||
{"1000 routes, 3 coordinates, no alternatives, overview=full, steps=true",
|
||||
{{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}},
|
||||
{FloatLongitude{7.421844922513342}, FloatLatitude{43.73690777888953}},
|
||||
{FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}},
|
||||
RouteParameters::OverviewType::Full,
|
||||
true,
|
||||
std::nullopt},
|
||||
{"1000 routes, 2 coordinates, no alternatives, overview=full, steps=true",
|
||||
{{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}},
|
||||
{FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}},
|
||||
RouteParameters::OverviewType::Full,
|
||||
true,
|
||||
std::nullopt},
|
||||
{"1000 routes, 2 coordinates, 3 alternatives, overview=full, steps=true",
|
||||
{{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}},
|
||||
{FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}},
|
||||
RouteParameters::OverviewType::Full,
|
||||
true,
|
||||
3},
|
||||
{"1000 routes, 3 coordinates, no alternatives, overview=false, steps=false",
|
||||
{{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}},
|
||||
{FloatLongitude{7.421844922513342}, FloatLatitude{43.73690777888953}},
|
||||
{FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}},
|
||||
RouteParameters::OverviewType::False,
|
||||
false,
|
||||
std::nullopt},
|
||||
{"1000 routes, 2 coordinates, no alternatives, overview=false, steps=false",
|
||||
{{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}},
|
||||
{FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}},
|
||||
RouteParameters::OverviewType::False,
|
||||
false,
|
||||
std::nullopt},
|
||||
{"1000 routes, 2 coordinates, 3 alternatives, overview=false, steps=false",
|
||||
{{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}},
|
||||
{FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}},
|
||||
RouteParameters::OverviewType::False,
|
||||
false,
|
||||
3},
|
||||
{"1000 routes, 3 coordinates, no alternatives, overview=false, steps=false, radius=750",
|
||||
{{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}},
|
||||
{FloatLongitude{7.421844922513342}, FloatLatitude{43.73690777888953}},
|
||||
{FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}},
|
||||
RouteParameters::OverviewType::False,
|
||||
false,
|
||||
std::nullopt,
|
||||
750},
|
||||
{"1000 routes, 2 coordinates, no alternatives, overview=false, steps=false, radius=750",
|
||||
{{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}},
|
||||
{FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}},
|
||||
RouteParameters::OverviewType::False,
|
||||
false,
|
||||
std::nullopt,
|
||||
750},
|
||||
{"1000 routes, 2 coordinates, 3 alternatives, overview=false, steps=false, radius=750",
|
||||
{{FloatLongitude{7.437602352715465}, FloatLatitude{43.75030522209604}},
|
||||
{FloatLongitude{7.412303912230966}, FloatLatitude{43.72851046529198}}},
|
||||
RouteParameters::OverviewType::False,
|
||||
false,
|
||||
3,
|
||||
750}
|
||||
|
||||
};
|
||||
|
||||
for (const auto &benchmark : benchmarks)
|
||||
{
|
||||
run_benchmark(benchmark);
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
std::cerr << "Error: " << e.what() << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
Loading…
Reference in New Issue
Block a user