diff options
author | Richard Hausman <richard.hausman@mongodb.com> | 2022-08-20 01:10:31 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-08-20 01:45:22 +0000 |
commit | 3f777924c271f91fdc9a878a2e70cc4f068d9014 (patch) | |
tree | d59fa770192347fb01073b057780bda7b1b4390d /src/mongo/bson/bson_bm.cpp | |
parent | a96f1436e02feea955565ac0ea39f8b56f087639 (diff) | |
download | mongo-3f777924c271f91fdc9a878a2e70cc4f068d9014.tar.gz |
SERVER-67521 Check for duplicate field names in BSON documents during validation
Diffstat (limited to 'src/mongo/bson/bson_bm.cpp')
-rw-r--r-- | src/mongo/bson/bson_bm.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/mongo/bson/bson_bm.cpp b/src/mongo/bson/bson_bm.cpp index f4a1064dbac..29d12bbd6d3 100644 --- a/src/mongo/bson/bson_bm.cpp +++ b/src/mongo/bson/bson_bm.cpp @@ -114,8 +114,32 @@ void BM_validate(benchmark::State& state) { state.SetBytesProcessed(totalSize); } +void BM_validate_contents(benchmark::State& state) { + BSONArrayBuilder builder; + auto len = state.range(0); + size_t totalSize = 0; + for (auto j = 0; j < len; j++) + builder.append(buildSampleObj(j)); + BSONObj array = builder.done(); + + const auto& elem = array[0].Obj(); + auto status = validateBSON(elem.objdata(), elem.objsize(), BSONValidateMode::kFull); + if (!status.isOK()) + LOGV2(6752100, "Validate failed", "elem"_attr = elem, "status"_attr = status); + invariant(status.isOK()); + + for (auto _ : state) { + benchmark::ClobberMemory(); + benchmark::DoNotOptimize( + validateBSON(array.objdata(), array.objsize(), BSONValidateMode::kFull)); + totalSize += array.objsize(); + } + state.SetBytesProcessed(totalSize); +} + BENCHMARK(BM_arrayBuilder)->Ranges({{{1}, {100'000}}}); BENCHMARK(BM_arrayLookup)->Ranges({{{1}, {100'000}}}); BENCHMARK(BM_validate)->Ranges({{{1}, {1'000}}}); +BENCHMARK(BM_validate_contents)->Ranges({{{1}, {1'000}}}); } // namespace mongo |