simdjson/benchmark/partial_tweets/simdjson_dom.h

43 lines
1005 B
C
Raw Normal View History

#pragma once
#if SIMDJSON_EXCEPTIONS
#include "partial_tweets.h"
namespace partial_tweets {
using namespace simdjson;
struct simdjson_dom {
2021-01-07 06:38:12 +08:00
using StringType=std::string_view;
dom::parser parser{};
simdjson_really_inline uint64_t nullable_int(dom::element element) {
if (element.is_null()) { return 0; }
return element;
}
2021-01-07 06:38:12 +08:00
bool run(simdjson::padded_string &json, std::vector<tweet<std::string_view>> &result) {
for (dom::element tweet : parser.parse(json)["statuses"]) {
auto user = tweet["user"];
2021-01-07 06:38:12 +08:00
result.emplace_back(partial_tweets::tweet<std::string_view>{
tweet["created_at"],
tweet["id"],
tweet["text"],
nullable_int(tweet["in_reply_to_status_id"]),
{ user["id"], user["screen_name"] },
tweet["retweet_count"],
tweet["favorite_count"]
});
}
return true;
}
};
2021-01-06 02:45:49 +08:00
BENCHMARK_TEMPLATE(partial_tweets, simdjson_dom)->UseManualTime();
} // namespace partial_tweets
#endif // SIMDJSON_EXCEPTIONS