This commit is contained in:
Siarhei Fedartsou 2022-09-28 19:02:27 +02:00
parent ef8f3d7508
commit 463663b05e
2 changed files with 156 additions and 0 deletions

View File

@ -30,6 +30,18 @@ target_link_libraries(match-bench
${TBB_LIBRARIES} ${TBB_LIBRARIES}
${MAYBE_SHAPEFILE}) ${MAYBE_SHAPEFILE})
add_executable(json-render-bench
EXCLUDE_FROM_ALL
json_render.cpp
$<TARGET_OBJECTS:UTIL>)
target_link_libraries(json-render-bench
osrm
${BOOST_BASE_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
${TBB_LIBRARIES}
${MAYBE_SHAPEFILE})
add_executable(alias-bench add_executable(alias-bench
EXCLUDE_FROM_ALL EXCLUDE_FROM_ALL
${AliasBenchmarkSources} ${AliasBenchmarkSources}
@ -41,6 +53,8 @@ target_link_libraries(alias-bench
${TBB_LIBRARIES} ${TBB_LIBRARIES}
${MAYBE_SHAPEFILE}) ${MAYBE_SHAPEFILE})
add_executable(packedvector-bench add_executable(packedvector-bench
EXCLUDE_FROM_ALL EXCLUDE_FROM_ALL
${PackedVectorBenchmarkSources} ${PackedVectorBenchmarkSources}
@ -58,4 +72,5 @@ add_custom_target(benchmarks
rtree-bench rtree-bench
packedvector-bench packedvector-bench
match-bench match-bench
json-render-bench
alias-bench) alias-bench)

View File

@ -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 <cstdlib>
#include <iostream>
#include <sstream>
// #ifdef _WIN32
// #pragma optimize("", off)
// template <class T> void dont_optimize_away(T &&datum) { T local = datum; }
// #pragma optimize("", on)
// #else
// template <class T> void dont_optimize_away(T &&datum) { asm volatile("" : "+r"(datum)); }
// #endif
// template <std::size_t num_rounds, std::size_t num_entries, typename VectorT>
// auto measure_random_access()
// {
// std::vector<std::size_t> 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<std::size_t>(0, num_rounds))
// {
// for (auto idx : util::irange<std::size_t>(0, num_entries))
// {
// vector[indices[idx]] = idx + round;
// }
// }
// TIMER_STOP(write);
// TIMER_START(read);
// auto sum = 0;
// for (auto round : util::irange<std::size_t>(0, num_rounds))
// {
// sum = round;
// for (auto idx : util::irange<std::size_t>(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;
}