2021-01-05 04:21:50 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#if SIMDJSON_EXCEPTIONS
|
|
|
|
|
|
|
|
#include "find_tweet.h"
|
|
|
|
|
|
|
|
namespace find_tweet {
|
|
|
|
|
|
|
|
using namespace simdjson;
|
|
|
|
using namespace simdjson::builtin;
|
|
|
|
|
2021-01-05 12:20:24 +08:00
|
|
|
struct simdjson_ondemand {
|
2021-01-05 04:21:50 +08:00
|
|
|
ondemand::parser parser{};
|
2021-01-05 12:20:24 +08:00
|
|
|
|
2021-01-06 03:31:34 +08:00
|
|
|
bool run(simdjson::padded_string &json, uint64_t find_id, std::string_view &result) {
|
2021-01-05 04:21:50 +08:00
|
|
|
// Walk the document, parsing as we go
|
|
|
|
auto doc = parser.iterate(json);
|
|
|
|
for (auto tweet : doc.find_field("statuses")) {
|
|
|
|
if (uint64_t(tweet.find_field("id")) == find_id) {
|
2021-01-06 03:31:34 +08:00
|
|
|
result = tweet.find_field("text");
|
2021-01-05 04:21:50 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-01-06 02:45:49 +08:00
|
|
|
BENCHMARK_TEMPLATE(find_tweet, simdjson_ondemand)->UseManualTime();
|
2021-01-05 04:21:50 +08:00
|
|
|
|
|
|
|
} // namespace find_tweet
|
|
|
|
|
|
|
|
#endif // SIMDJSON_EXCEPTIONS
|