Use find_field in benchmark
This commit is contained in:
parent
195acc3e45
commit
e7e09e444c
|
@ -33,15 +33,15 @@ simdjson_really_inline bool OnDemand::Run(const padded_string &json) {
|
|||
ids.clear();
|
||||
// Walk the document, parsing as we go
|
||||
auto doc = parser.iterate(json);
|
||||
for (ondemand::object tweet : doc["statuses"]) {
|
||||
for (ondemand::object tweet : doc.find_field("statuses")) {
|
||||
// We believe that all statuses have a matching
|
||||
// user, and we are willing to throw when they do not.
|
||||
ids.push_back(tweet["user"]["id"]);
|
||||
ids.push_back(tweet.find_field("user").find_field("id"));
|
||||
// Not all tweets have a "retweeted_status", but when they do
|
||||
// we want to go and find the user within.
|
||||
auto retweet = tweet["retweeted_status"];
|
||||
auto retweet = tweet.find_field("retweeted_status");
|
||||
if(!retweet.error()) {
|
||||
ids.push_back(retweet["user"]["id"]);
|
||||
ids.push_back(retweet.find_field("user").find_field("id"));
|
||||
}
|
||||
}
|
||||
remove_duplicates(ids);
|
||||
|
|
|
@ -33,9 +33,9 @@ simdjson_really_inline bool OnDemand::Run(const padded_string &json) {
|
|||
text = "";
|
||||
// Walk the document, parsing as we go
|
||||
auto doc = parser.iterate(json);
|
||||
for (ondemand::object tweet : doc["statuses"]) {
|
||||
if (uint64_t(tweet["id"]) == TWEET_ID) {
|
||||
text = tweet["text"];
|
||||
for (ondemand::object tweet : doc.find_field("statuses")) {
|
||||
if (uint64_t(tweet.find_field("id")) == TWEET_ID) {
|
||||
text = tweet.find_field("text");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,8 +27,8 @@ simdjson_really_inline bool OnDemand::Run(const padded_string &json) {
|
|||
using std::endl;
|
||||
|
||||
auto doc = parser.iterate(json);
|
||||
for (ondemand::object coord : doc["coordinates"]) {
|
||||
container.emplace_back(my_point{coord["x"], coord["y"], coord["z"]});
|
||||
for (ondemand::object coord : doc.find_field("coordinates")) {
|
||||
container.emplace_back(my_point{coord.find_field("x"), coord.find_field("y"), coord.find_field("z")});
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -56,10 +56,10 @@ simdjson_really_inline bool OnDemand::Run(const padded_string &json) {
|
|||
count = 0;
|
||||
|
||||
auto doc = parser.iterate(json);
|
||||
for (ondemand::object coord : doc["coordinates"]) {
|
||||
sum.x += double(coord["x"]);
|
||||
sum.y += double(coord["y"]);
|
||||
sum.z += double(coord["z"]);
|
||||
for (ondemand::object coord : doc.find_field("coordinates")) {
|
||||
sum.x += double(coord.find_field("x"));
|
||||
sum.y += double(coord.find_field("y"));
|
||||
sum.z += double(coord.find_field("z"));
|
||||
count++;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ simdjson_really_inline bool OnDemand::Run(const padded_string &json) {
|
|||
|
||||
auto doc = parser.iterate(json);
|
||||
for (ondemand::object coord : doc) {
|
||||
container.emplace_back(my_point{coord["x"], coord["y"], coord["z"]});
|
||||
container.emplace_back(my_point{coord.find_field("x"), coord.find_field("y"), coord.find_field("z")});
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -54,9 +54,9 @@ simdjson_really_inline bool OnDemand::Run(const padded_string &json) {
|
|||
|
||||
auto doc = parser.iterate(json);
|
||||
for (ondemand::object coord : doc.get_array()) {
|
||||
sum.x += double(coord["x"]);
|
||||
sum.y += double(coord["y"]);
|
||||
sum.z += double(coord["z"]);
|
||||
sum.x += double(coord.find_field("x"));
|
||||
sum.y += double(coord.find_field("y"));
|
||||
sum.z += double(coord.find_field("z"));
|
||||
count++;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ private:
|
|||
}
|
||||
|
||||
simdjson_really_inline twitter_user read_user(ondemand::object user) {
|
||||
return { user["id"], user["screen_name"] };
|
||||
return { user.find_field("id"), user.find_field("screen_name") };
|
||||
}
|
||||
|
||||
static inline bool displayed_implementation = false;
|
||||
|
@ -43,15 +43,15 @@ simdjson_really_inline bool OnDemand::Run(const padded_string &json) {
|
|||
|
||||
// Walk the document, parsing the tweets as we go
|
||||
auto doc = parser.iterate(json);
|
||||
for (ondemand::object tweet : doc["statuses"]) {
|
||||
for (ondemand::object tweet : doc.find_field("statuses")) {
|
||||
tweets.emplace_back(partial_tweets::tweet{
|
||||
tweet["created_at"],
|
||||
tweet["id"],
|
||||
tweet["text"],
|
||||
nullable_int(tweet["in_reply_to_status_id"]),
|
||||
read_user(tweet["user"]),
|
||||
tweet["retweet_count"],
|
||||
tweet["favorite_count"]
|
||||
tweet.find_field("created_at"),
|
||||
tweet.find_field("id"),
|
||||
tweet.find_field("text"),
|
||||
nullable_int(tweet.find_field("in_reply_to_status_id")),
|
||||
read_user(tweet.find_field("user")),
|
||||
tweet.find_field("retweet_count"),
|
||||
tweet.find_field("favorite_count")
|
||||
});
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -18,7 +18,7 @@ simdjson_really_inline simdjson_result<value> object::operator[](const std::stri
|
|||
return find_field_unordered(key);
|
||||
}
|
||||
simdjson_really_inline simdjson_result<value> object::operator[](const std::string_view key) && noexcept {
|
||||
return find_field_unordered(key);
|
||||
return std::forward<object>(*this).find_field_unordered(key);
|
||||
}
|
||||
simdjson_really_inline simdjson_result<value> object::find_field(const std::string_view key) & noexcept {
|
||||
bool has_value;
|
||||
|
|
Loading…
Reference in New Issue