From 463663b05eefa1fe856db5fe77f96474a52e87d4 Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Wed, 28 Sep 2022 19:02:27 +0200 Subject: [PATCH] wip --- src/benchmarks/CMakeLists.txt | 15 ++++ src/benchmarks/json_render.cpp | 141 +++++++++++++++++++++++++++++++++ 2 files changed, 156 insertions(+) create mode 100644 src/benchmarks/json_render.cpp diff --git a/src/benchmarks/CMakeLists.txt b/src/benchmarks/CMakeLists.txt index 6a6986a22..233445c4b 100644 --- a/src/benchmarks/CMakeLists.txt +++ b/src/benchmarks/CMakeLists.txt @@ -30,6 +30,18 @@ target_link_libraries(match-bench ${TBB_LIBRARIES} ${MAYBE_SHAPEFILE}) +add_executable(json-render-bench + EXCLUDE_FROM_ALL + json_render.cpp + $) + +target_link_libraries(json-render-bench + osrm + ${BOOST_BASE_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} + ${TBB_LIBRARIES} + ${MAYBE_SHAPEFILE}) + add_executable(alias-bench EXCLUDE_FROM_ALL ${AliasBenchmarkSources} @@ -41,6 +53,8 @@ target_link_libraries(alias-bench ${TBB_LIBRARIES} ${MAYBE_SHAPEFILE}) + + add_executable(packedvector-bench EXCLUDE_FROM_ALL ${PackedVectorBenchmarkSources} @@ -58,4 +72,5 @@ add_custom_target(benchmarks rtree-bench packedvector-bench match-bench + json-render-bench alias-bench) diff --git a/src/benchmarks/json_render.cpp b/src/benchmarks/json_render.cpp new file mode 100644 index 000000000..c5b773fec --- /dev/null +++ b/src/benchmarks/json_render.cpp @@ -0,0 +1,141 @@ + +#include "util/json_container.hpp" +#include "util/json_renderer.hpp" +#include "util/timing_util.hpp" +#include "osrm/json_container.hpp" +#include +#include +#include + +// #ifdef _WIN32 +// #pragma optimize("", off) +// template void dont_optimize_away(T &&datum) { T local = datum; } +// #pragma optimize("", on) +// #else +// template void dont_optimize_away(T &&datum) { asm volatile("" : "+r"(datum)); } +// #endif + +// template +// auto measure_random_access() +// { +// std::vector indices(num_entries); +// std::iota(indices.begin(), indices.end(), 0); +// std::mt19937 g(1337); +// std::shuffle(indices.begin(), indices.end(), g); + +// VectorT vector(num_entries); + +// TIMER_START(write); +// for (auto round : util::irange(0, num_rounds)) +// { +// for (auto idx : util::irange(0, num_entries)) +// { +// vector[indices[idx]] = idx + round; +// } +// } +// TIMER_STOP(write); + +// TIMER_START(read); +// auto sum = 0; +// for (auto round : util::irange(0, num_rounds)) +// { +// sum = round; +// for (auto idx : util::irange(0, num_entries)) +// { +// sum += vector[indices[idx]]; +// } +// dont_optimize_away(sum); +// } +// TIMER_STOP(read); + +// return Measurement{TIMER_MSEC(write), TIMER_MSEC(read)}; +// } + +int main(int, char **) +{ + using namespace osrm; + + const auto location = json::Array{{{7.437070}, {43.749248}}}; + + json::Object reference{ + {{"code", "Ok"}, + {"waypoints", + json::Array{{json::Object{{{"name", "Boulevard du Larvotto"}, + {"location", location}, + {"distance", round(0.137249 * 1000000)}, + {"hint", ""}}}, + json::Object{{{"name", "Boulevard du Larvotto"}, + {"location", location}, + {"distance", round(0.137249 * 1000000)}, + {"hint", ""}}}}}}, + {"routes", + json::Array{{json::Object{ + {{"distance", 0.}, + {"duration", 0.}, + {"weight", 0.}, + {"weight_name", "routability"}, + {"geometry", "yw_jGupkl@??"}, + {"legs", + json::Array{{json::Object{ + {{"distance", 0.}, + {"duration", 0.}, + {"weight", 0.}, + {"summary", "Boulevard du Larvotto"}, + {"steps", + json::Array{{{json::Object{{{"duration", 0.}, + {"distance", 0.}, + {"weight", 0.}, + {"geometry", "yw_jGupkl@??"}, + {"name", "Boulevard du Larvotto"}, + {"mode", "driving"}, + {"driving_side", "right"}, + {"maneuver", + json::Object{{ + {"location", location}, + {"bearing_before", 0}, + {"bearing_after", 238}, + {"type", "depart"}, + }}}, + {"intersections", + json::Array{{json::Object{ + {{"location", location}, + {"bearings", json::Array{{238}}}, + {"entry", json::Array{{json::True()}}}, + {"out", 0}}}}}}}}}, + + json::Object{{{"duration", 0.}, + {"distance", 0.}, + {"weight", 0.}, + {"geometry", "yw_jGupkl@"}, + {"name", "Boulevard du Larvotto"}, + {"mode", "driving"}, + {"driving_side", "right"}, + {"maneuver", + json::Object{{{"location", location}, + {"bearing_before", 238}, + {"bearing_after", 0}, + {"type", "arrive"}}}}, + {"intersections", + json::Array{{json::Object{ + {{"location", location}, + {"bearings", json::Array{{58}}}, + {"entry", json::Array{{json::True()}}}, + {"in", 0}}}}}} + + }}}}}}}}}}}}}}}}}; +json::Array arr; +for (size_t index = 0; index < 256; ++index) { + arr.values.push_back(reference); +} +json::Object obj{{{"arr", arr}}}; +std::string ss; +TIMER_START(create_object); + json::render(ss, obj); + //std::string s{ss.begin(), ss.end()}; +TIMER_STOP(create_object); +std::cout << TIMER_MSEC(create_object) << "ms" + << std::endl; + // (void)s; + // std::cerr << ss << "\n"; + return EXIT_SUCCESS; +}