Files
simdjson-simdjson/benchmark/accessor_performance/runtime_accessors.h
Francisco Geiman Thiesen 58c92d6d82 Adding support for compiled json path + json pointer (reflection based) (#2483)
* Adding compile time json path

* using string_view

* Adding support for compile-time json pointer as well.

* Removing unnecessary comment

* Tests now working, still will re-review.

* Adding documentation on the compile-time json path/pointer parsing feature.

* Adding benchmark showing the significant performance advantage of using compiled paths whenever you have them a priori.

* going for JSONPath (correct wording).

* minor update (mostly doc)

---------

Co-authored-by: Daniel Lemire <daniel@lemire.me>
2025-10-27 16:52:41 -04:00

54 lines
1.4 KiB
C++

#pragma once
#if SIMDJSON_EXCEPTIONS
#include "accessor_benchmark.h"
namespace accessor_performance {
using namespace simdjson;
struct runtime_at_path_simple {
ondemand::parser parser{};
bool run(simdjson::padded_string &json, std::string &result_str, int64_t&, double&, bool&) {
auto doc = parser.iterate(json);
std::string_view name;
if (doc.at_path(".name").get(name) != SUCCESS) return false;
result_str = name;
return true;
}
};
struct runtime_at_path_nested {
ondemand::parser parser{};
bool run(simdjson::padded_string &json, std::string &result_str, int64_t&, double&, bool&) {
auto doc = parser.iterate(json);
std::string_view city;
if (doc.at_path(".address.city").get(city) != SUCCESS) return false;
result_str = city;
return true;
}
};
struct runtime_at_path_deep {
ondemand::parser parser{};
bool run(simdjson::padded_string &json, std::string&, int64_t&, double &result_dbl, bool&) {
auto doc = parser.iterate(json);
double lat;
if (doc.at_path(".address.coordinates.lat").get(lat) != SUCCESS) return false;
result_dbl = lat;
return true;
}
};
BENCHMARK_TEMPLATE(accessor_simple, runtime_at_path_simple)->UseManualTime();
BENCHMARK_TEMPLATE(accessor_nested, runtime_at_path_nested)->UseManualTime();
BENCHMARK_TEMPLATE(accessor_deep, runtime_at_path_deep)->UseManualTime();
} // namespace accessor_performance
#endif // SIMDJSON_EXCEPTIONS