| 240 | } |
| 241 | |
| 242 | static 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 | |
| 270 | BENCHMARK(ChunkJSONPrettyPrinted); |
| 271 | BENCHMARK(ChunkJSONPrettyPrintedMultipleBlocks); |
nothing calls this directly
no test coverage detected