MCPcopy Create free account
hub / github.com/apache/arrow / ParseJSONFields

Function ParseJSONFields

cpp/src/arrow/json/parser_benchmark.cc:193–219  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

191}
192
193static void ParseJSONFields(benchmark::State& state) { // NOLINT non-const reference
194 const bool ordered = !!state.range(0);
195 const bool with_schema = !!state.range(1);
196 const double sparsity = state.range(2) / 100.0;
197 const auto num_fields = static_cast<int>(state.range(3));
198
199 // This would generate approximately 400 kB of JSON data
200 int32_t num_rows = static_cast<int32_t>(2e4 / (1.0 - sparsity) / num_fields);
201 // ... however, we want enough rows to make setup/finish overhead negligible
202 num_rows = std::max<int32_t>(num_rows, 200);
203 // In the end, we will empirically generate between 400 kB and 4 MB of JSON data.
204
205 auto fields = GenerateTestFields(num_fields, 10);
206
207 auto parse_options = ParseOptions::Defaults();
208 if (with_schema) {
209 parse_options.explicit_schema = schema(fields);
210 parse_options.unexpected_field_behavior = UnexpectedFieldBehavior::Error;
211 }
212
213 auto gen_options = GenerateOptions::Defaults();
214 gen_options.field_probability = 1.0 - sparsity;
215 gen_options.randomize_field_order = !ordered;
216
217 auto json = GenerateTestData(fields, num_rows, gen_options);
218 BenchmarkJSONParsing(state, std::make_shared<Buffer>(json), parse_options);
219}
220
221BENCHMARK(ChunkJSONPrettyPrinted);
222BENCHMARK(ChunkJSONLineDelimited);

Callers

nothing calls this directly

Calls 5

GenerateTestFieldsFunction · 0.85
BenchmarkJSONParsingFunction · 0.85
GenerateTestDataFunction · 0.70
DefaultsFunction · 0.50
schemaFunction · 0.50

Tested by

no test coverage detected