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

Function ParseJSONFields

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

Source from the content-addressed store, hash-verified

240}
241
242static void ParseJSONFields(benchmark::State& state) { // NOLINT non-const reference
243 const bool ordered = !!state.range(0);
244 const bool with_schema = !!state.range(1);
245 const double sparsity = state.range(2) / 100.0;
246 const auto num_fields = static_cast<int>(state.range(3));
247
248 // This would generate approximately 400 kB of JSON data
249 int32_t num_rows = static_cast<int32_t>(2e4 / (1.0 - sparsity) / num_fields);
250 // ... however, we want enough rows to make setup/finish overhead negligible
251 num_rows = std::max<int32_t>(num_rows, 200);
252 // In the end, we will empirically generate between 400 kB and 4 MB of JSON data.
253
254 auto fields = GenerateTestFields(num_fields, 10);
255
256 auto parse_options = ParseOptions::Defaults();
257 if (with_schema) {
258 parse_options.explicit_schema = schema(fields);
259 parse_options.unexpected_field_behavior = UnexpectedFieldBehavior::Error;
260 }
261
262 auto gen_options = GenerateOptions::Defaults();
263 gen_options.field_probability = 1.0 - sparsity;
264 gen_options.randomize_field_order = !ordered;
265
266 auto json = GenerateTestData(fields, num_rows, gen_options);
267 BenchmarkJSONParsing(state, std::make_shared<Buffer>(json), parse_options);
268}
269
270BENCHMARK(ChunkJSONPrettyPrinted);
271BENCHMARK(ChunkJSONPrettyPrintedMultipleBlocks);

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