mirror of
https://github.com/simdjson/simdjson
synced 2026-06-08 17:27:07 +00:00
5510089d45
* Rename simdjson_really_inline -> simdjson_inline I want to change the simdjson_really_inline macro to sometimes not force inlining. After that upcoming change, the name simdjson_really_inline will no longer makes sense. Rename simdjson_really_inline to simdjson_inline. This patch should not change semantics; simdjson_inline still forces inlining as before. Some functions still need to be really inlined for ABI reasons. (GCC's -Wpsabi complains otherwise.) Leave those functions marked as simdjson_really_inline. * Improve build times for debug builds simdjson_inline is used for most simdjson functions. It forces inlining. In unoptimized/debug builds, this can lead to a lot of machine code being generated (especially with Address Sanitizer), causing slow compilation. Change simdjson_inline to force inlining only for optimized builds. Sometimes, the programmer might want a slightly-optimized build and want fast compilation (e.g. GCC's -Og mode). Allow simdjson users to define the simdjson_inline macro themselves (e.g. on the command line: -Dsimdjson_inline=inline) in cases where the default behavior is undesired. This patch reduced build times by over 75% for ondemand_object_tests.cpp with GCC 9.4.0 and CMAKE_BUILD_TYPE=Debug on my AMD 5950X: Before: 6.885 6.683 6.971 6.957 6.949 seconds (5 samples) After: 1.492 1.551 1.494 1.490 1.531 seconds (5 samples)
65 lines
1.6 KiB
C++
65 lines
1.6 KiB
C++
#pragma once
|
|
|
|
#ifdef SIMDJSON_COMPETITION_SAJSON
|
|
|
|
#include "large_random.h"
|
|
|
|
namespace large_random {
|
|
|
|
struct sajson {
|
|
static constexpr diff_flags DiffFlags = diff_flags::IMPRECISE_FLOATS;
|
|
|
|
size_t ast_buffer_size{0};
|
|
size_t *ast_buffer{nullptr};
|
|
~sajson() { free(ast_buffer); }
|
|
|
|
simdjson_inline double get_double(const ::sajson::value &obj, std::string_view key) {
|
|
using namespace sajson;
|
|
|
|
auto val = obj.get_value_of_key({key.data(), key.length()});
|
|
switch (val.get_type()) {
|
|
case TYPE_INTEGER:
|
|
case TYPE_DOUBLE:
|
|
return val.get_number_value();
|
|
default:
|
|
throw "field not double";
|
|
}
|
|
}
|
|
|
|
bool run(simdjson::padded_string &json, std::vector<point> &result) {
|
|
using namespace sajson;
|
|
|
|
if (!ast_buffer) {
|
|
ast_buffer_size = json.size();
|
|
ast_buffer = (size_t *)std::malloc(ast_buffer_size * sizeof(size_t));
|
|
}
|
|
auto doc = parse(
|
|
bounded_allocation(ast_buffer, ast_buffer_size),
|
|
mutable_string_view(json.size(), json.data())
|
|
);
|
|
if (!doc.is_valid()) { return false; }
|
|
|
|
auto points = doc.get_root();
|
|
if (points.get_type() != TYPE_ARRAY) { return false; }
|
|
|
|
for (size_t i=0; i<points.get_length(); i++) {
|
|
auto point = points.get_array_element(i);
|
|
if (point.get_type() != TYPE_OBJECT) { return false; }
|
|
result.emplace_back(json_benchmark::point{
|
|
get_double(point, "x"),
|
|
get_double(point, "y"),
|
|
get_double(point, "z")
|
|
});
|
|
}
|
|
|
|
return true;
|
|
}
|
|
};
|
|
|
|
BENCHMARK_TEMPLATE(large_random, sajson)->UseManualTime();
|
|
|
|
} // namespace large_random
|
|
|
|
#endif // SIMDJSON_COMPETITION_SAJSON
|
|
|