Skip to content

Commit 6cd8fb7

Browse files
authored
Adding a getline benchmark (simdjson#344)
1 parent ce824f8 commit 6cd8fb7

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

‎benchmark/parsingcompetition.cpp‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,18 @@ bool fastjson_parse(const char *input) {
6060
// end of fastjson stuff
6161
#endif
6262

63+
size_t sum_line_lengths(char * data, size_t length) {
64+
std::stringstream is;
65+
is.rdbuf()->pubsetbuf(data, length);
66+
std::string line;
67+
size_t sumofalllinelengths{0};
68+
while(getline(is, line)) {
69+
sumofalllinelengths += line.size();
70+
}
71+
return sumofalllinelengths;
72+
}
73+
74+
6375
int main(int argc, char *argv[]) {
6476
bool verbose = false;
6577
bool just_data = false;
@@ -117,6 +129,12 @@ int main(int argc, char *argv[]) {
117129
printf("%-42s %20s %20s %20s %20s \n", "name", "cycles_per_byte",
118130
"cycles_per_byte_err", "gb_per_s", "gb_per_s_err");
119131
}
132+
if (!just_data) {
133+
size_t lc = sum_line_lengths(p.data(), p.size());
134+
BEST_TIME("getline ",sum_line_lengths(p.data(), p.size()) , lc, ,
135+
repeat, volume, !just_data);
136+
}
137+
120138
if (!just_data)
121139
BEST_TIME("simdjson (dynamic mem) ", build_parsed_json(p).is_valid(), true,
122140
, repeat, volume, !just_data);

0 commit comments

Comments
 (0)