This commit is contained in:
Siarhei Fedartsou 2024-11-03 13:07:28 +01:00
parent 5b69c0a7f2
commit d5ab66496c
3 changed files with 68 additions and 61 deletions

View File

@ -104,7 +104,7 @@ using Value = std::variant<String, Number, Object, Array, True, False, Null>;
*/ */
struct Object struct Object
{ {
std::unordered_map<std::string, Value> values; std::unordered_map<std::string_view, Value> values;
}; };
/** /**

View File

@ -54,80 +54,80 @@ function run_benchmarks_for_folder {
BENCHMARKS_FOLDER="$BINARIES_FOLDER/src/benchmarks" BENCHMARKS_FOLDER="$BINARIES_FOLDER/src/benchmarks"
# echo "Running match-bench MLD" echo "Running match-bench MLD"
# $BENCHMARKS_FOLDER/match-bench "$FOLDER/test/data/mld/monaco.osrm" mld > "$RESULTS_FOLDER/match_mld.bench" $BENCHMARKS_FOLDER/match-bench "$FOLDER/test/data/mld/monaco.osrm" mld > "$RESULTS_FOLDER/match_mld.bench"
# echo "Running match-bench CH" echo "Running match-bench CH"
# $BENCHMARKS_FOLDER/match-bench "$FOLDER/test/data/ch/monaco.osrm" ch > "$RESULTS_FOLDER/match_ch.bench" $BENCHMARKS_FOLDER/match-bench "$FOLDER/test/data/ch/monaco.osrm" ch > "$RESULTS_FOLDER/match_ch.bench"
# echo "Running route-bench MLD" echo "Running route-bench MLD"
# $BENCHMARKS_FOLDER/route-bench "$FOLDER/test/data/mld/monaco.osrm" mld > "$RESULTS_FOLDER/route_mld.bench" $BENCHMARKS_FOLDER/route-bench "$FOLDER/test/data/mld/monaco.osrm" mld > "$RESULTS_FOLDER/route_mld.bench"
# echo "Running route-bench CH" echo "Running route-bench CH"
# $BENCHMARKS_FOLDER/route-bench "$FOLDER/test/data/ch/monaco.osrm" ch > "$RESULTS_FOLDER/route_ch.bench" $BENCHMARKS_FOLDER/route-bench "$FOLDER/test/data/ch/monaco.osrm" ch > "$RESULTS_FOLDER/route_ch.bench"
# echo "Running alias" echo "Running alias"
# $BENCHMARKS_FOLDER/alias-bench > "$RESULTS_FOLDER/alias.bench" $BENCHMARKS_FOLDER/alias-bench > "$RESULTS_FOLDER/alias.bench"
# echo "Running json-render-bench" echo "Running json-render-bench"
$BENCHMARKS_FOLDER/json-render-bench "$FOLDER/test/data/portugal_to_korea.json" #> "$RESULTS_FOLDER/json-render.bench" $BENCHMARKS_FOLDER/json-render-bench "$FOLDER/test/data/portugal_to_korea.json" #> "$RESULTS_FOLDER/json-render.bench"
echo "Running packedvector-bench" echo "Running packedvector-bench"
# $BENCHMARKS_FOLDER/packedvector-bench > "$RESULTS_FOLDER/packedvector.bench" $BENCHMARKS_FOLDER/packedvector-bench > "$RESULTS_FOLDER/packedvector.bench"
# echo "Running rtree-bench" echo "Running rtree-bench"
# $BENCHMARKS_FOLDER/rtree-bench "$FOLDER/test/data/monaco.osrm.ramIndex" "$FOLDER/test/data/monaco.osrm.fileIndex" "$FOLDER/test/data/monaco.osrm.nbg_nodes" > "$RESULTS_FOLDER/rtree.bench" $BENCHMARKS_FOLDER/rtree-bench "$FOLDER/test/data/monaco.osrm.ramIndex" "$FOLDER/test/data/monaco.osrm.fileIndex" "$FOLDER/test/data/monaco.osrm.nbg_nodes" > "$RESULTS_FOLDER/rtree.bench"
cp -rf $OSM_PBF $FOLDER/data.osm.pbf cp -rf $OSM_PBF $FOLDER/data.osm.pbf
echo "Running osrm-extract" echo "Running osrm-extract"
measure_peak_ram_and_time "$BINARIES_FOLDER/osrm-extract -p $FOLDER/profiles/car.lua $FOLDER/data.osm.pbf" "$RESULTS_FOLDER/osrm_extract.bench" measure_peak_ram_and_time "$BINARIES_FOLDER/osrm-extract -p $FOLDER/profiles/car.lua $FOLDER/data.osm.pbf" "$RESULTS_FOLDER/osrm_extract.bench"
# # echo "Running osrm-partition" echo "Running osrm-partition"
# measure_peak_ram_and_time "$BINARIES_FOLDER/osrm-partition $FOLDER/data.osrm" "$RESULTS_FOLDER/osrm_partition.bench" measure_peak_ram_and_time "$BINARIES_FOLDER/osrm-partition $FOLDER/data.osrm" "$RESULTS_FOLDER/osrm_partition.bench"
# echo "Running osrm-customize" echo "Running osrm-customize"
# measure_peak_ram_and_time "$BINARIES_FOLDER/osrm-customize $FOLDER/data.osrm" "$RESULTS_FOLDER/osrm_customize.bench" measure_peak_ram_and_time "$BINARIES_FOLDER/osrm-customize $FOLDER/data.osrm" "$RESULTS_FOLDER/osrm_customize.bench"
# echo "Running osrm-contract" echo "Running osrm-contract"
# measure_peak_ram_and_time "$BINARIES_FOLDER/osrm-contract $FOLDER/data.osrm" "$RESULTS_FOLDER/osrm_contract.bench" measure_peak_ram_and_time "$BINARIES_FOLDER/osrm-contract $FOLDER/data.osrm" "$RESULTS_FOLDER/osrm_contract.bench"
# for ALGORITHM in ch mld; do for ALGORITHM in ch mld; do
# for BENCH in nearest table trip route match; do for BENCH in nearest table trip route match; do
# echo "Running node $BENCH $ALGORITHM" echo "Running node $BENCH $ALGORITHM"
# START=$(date +%s.%N) START=$(date +%s.%N)
# node $SCRIPTS_FOLDER/scripts/ci/bench.js $FOLDER/lib/binding/node_osrm.node $FOLDER/data.osrm $ALGORITHM $BENCH $GPS_TRACES > "$RESULTS_FOLDER/node_${BENCH}_${ALGORITHM}.bench" 5 node $SCRIPTS_FOLDER/scripts/ci/bench.js $FOLDER/lib/binding/node_osrm.node $FOLDER/data.osrm $ALGORITHM $BENCH $GPS_TRACES > "$RESULTS_FOLDER/node_${BENCH}_${ALGORITHM}.bench" 5
# END=$(date +%s.%N) END=$(date +%s.%N)
# DIFF=$(echo "$END - $START" | bc) DIFF=$(echo "$END - $START" | bc)
# echo "Took: ${DIFF}s" echo "Took: ${DIFF}s"
# done done
# done done
# for ALGORITHM in ch mld; do for ALGORITHM in ch mld; do
# for BENCH in nearest table trip route match; do for BENCH in nearest table trip route match; do
# echo "Running random $BENCH $ALGORITHM" echo "Running random $BENCH $ALGORITHM"
# START=$(date +%s.%N) START=$(date +%s.%N)
# $BENCHMARKS_FOLDER/bench "$FOLDER/data.osrm" $ALGORITHM $GPS_TRACES ${BENCH} > "$RESULTS_FOLDER/random_${BENCH}_${ALGORITHM}.bench" 5 || true $BENCHMARKS_FOLDER/bench "$FOLDER/data.osrm" $ALGORITHM $GPS_TRACES ${BENCH} > "$RESULTS_FOLDER/random_${BENCH}_${ALGORITHM}.bench" 5 || true
# END=$(date +%s.%N) END=$(date +%s.%N)
# DIFF=$(echo "$END - $START" | bc) DIFF=$(echo "$END - $START" | bc)
# echo "Took: ${DIFF}s" echo "Took: ${DIFF}s"
# done done
# done done
# for ALGORITHM in ch mld; do for ALGORITHM in ch mld; do
# $BINARIES_FOLDER/osrm-routed --algorithm $ALGORITHM $FOLDER/data.osrm > /dev/null 2>&1 & $BINARIES_FOLDER/osrm-routed --algorithm $ALGORITHM $FOLDER/data.osrm > /dev/null 2>&1 &
# OSRM_ROUTED_PID=$! OSRM_ROUTED_PID=$!
# # wait for osrm-routed to start # wait for osrm-routed to start
# if ! curl --retry-delay 3 --retry 10 --retry-all-errors "http://127.0.0.1:5000/route/v1/driving/13.388860,52.517037;13.385983,52.496891?steps=true" > /dev/null 2>&1; then if ! curl --retry-delay 3 --retry 10 --retry-all-errors "http://127.0.0.1:5000/route/v1/driving/13.388860,52.517037;13.385983,52.496891?steps=true" > /dev/null 2>&1; then
# echo "osrm-routed failed to start for algorithm $ALGORITHM" echo "osrm-routed failed to start for algorithm $ALGORITHM"
# kill -9 $OSRM_ROUTED_PID kill -9 $OSRM_ROUTED_PID
# continue continue
# fi fi
# for METHOD in route nearest trip table match; do for METHOD in route nearest trip table match; do
# echo "Running e2e benchmark for $METHOD $ALGORITHM" echo "Running e2e benchmark for $METHOD $ALGORITHM"
# START=$(date +%s.%N) START=$(date +%s.%N)
# python3 $SCRIPTS_FOLDER/scripts/ci/e2e_benchmark.py --host http://localhost:5000 --method $METHOD --iterations 5 --num_requests 1000 --gps_traces_file_path $GPS_TRACES > $RESULTS_FOLDER/e2e_${METHOD}_${ALGORITHM}.bench python3 $SCRIPTS_FOLDER/scripts/ci/e2e_benchmark.py --host http://localhost:5000 --method $METHOD --iterations 5 --num_requests 1000 --gps_traces_file_path $GPS_TRACES > $RESULTS_FOLDER/e2e_${METHOD}_${ALGORITHM}.bench
# END=$(date +%s.%N) END=$(date +%s.%N)
# DIFF=$(echo "$END - $START" | bc) DIFF=$(echo "$END - $START" | bc)
# echo "Took: ${DIFF}s" echo "Took: ${DIFF}s"
# done done
# kill -9 $OSRM_ROUTED_PID kill -9 $OSRM_ROUTED_PID
# done done
} }
run_benchmarks_for_folder run_benchmarks_for_folder

View File

@ -9,12 +9,17 @@
#include <rapidjson/document.h> #include <rapidjson/document.h>
#include <sstream> #include <sstream>
#include <stdexcept> #include <stdexcept>
#include <unordered_set>
using namespace osrm; using namespace osrm;
namespace namespace
{ {
// we use std::string_view as a key in the object, so since here we have dynamic keys we have to "hold" them somewhere
// okay for tests...
static std::unordered_set<std::string> gKeysHolder;
void convert(const rapidjson::Value &value, json::Value &result) void convert(const rapidjson::Value &value, json::Value &result)
{ {
if (value.IsString()) if (value.IsString())
@ -32,7 +37,8 @@ void convert(const rapidjson::Value &value, json::Value &result)
{ {
json::Value member; json::Value member;
convert(itr->value, member); convert(itr->value, member);
object.values.emplace(itr->name.GetString(), std::move(member)); auto keyItr = gKeysHolder.emplace(itr->name.GetString()).first;
object.values.emplace(*keyItr, std::move(member));;
} }
result = std::move(object); result = std::move(object);
} }
@ -125,6 +131,7 @@ int main(int argc, char **argv)
if (std::string{out_vec.begin(), out_vec.end()} != out_str || out_str != out_ss_str) if (std::string{out_vec.begin(), out_vec.end()} != out_str || out_str != out_ss_str)
{ {
std::cerr << "Vector/string results are not equal\n";
throw std::logic_error("Vector/stringstream/string results are not equal"); throw std::logic_error("Vector/stringstream/string results are not equal");
} }
return EXIT_SUCCESS; return EXIT_SUCCESS;