diff options
author | Abseil Team <absl-team@google.com> | 2021-09-15 09:17:09 -0700 |
---|---|---|
committer | Derek Mauro <dmauro@google.com> | 2021-09-17 09:19:46 -0400 |
commit | de71511109d967000e68baedb75de104adb2b778 (patch) | |
tree | 132473fe6e5c4a248742d9a5a8ba75c7506dbe71 /absl/container/internal/raw_hash_set_test.cc | |
parent | 2f25e6ea5f91d1646aca2337719c9b4deb64100a (diff) | |
download | abseil-de71511109d967000e68baedb75de104adb2b778.tar.gz abseil-de71511109d967000e68baedb75de104adb2b778.tar.bz2 abseil-de71511109d967000e68baedb75de104adb2b778.zip |
Export of internal Abseil changes
--
3794fe8db7a8e5a17945a8d6e198cde1db1fed7d by Chris Kennelly <ckennelly@google.com>:
Record maximum reserve or rehash argument in hashtable statistics.
This makes it possible to identify containers that are large because of reserve
calls or ones that could have an opportunity for more precise capacity sizing.
PiperOrigin-RevId: 396851064
--
c3d247c08acfd45d8e19cfd8e6e841e16e38e23d by Abseil Team <absl-team@google.com>:
Remove extra semi-colon
PiperOrigin-RevId: 396823800
GitOrigin-RevId: 3794fe8db7a8e5a17945a8d6e198cde1db1fed7d
Change-Id: I9f26407c2dc6b3dff04f6f3e249571dd8ab288c3
Diffstat (limited to 'absl/container/internal/raw_hash_set_test.cc')
-rw-r--r-- | absl/container/internal/raw_hash_set_test.cc | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/absl/container/internal/raw_hash_set_test.cc b/absl/container/internal/raw_hash_set_test.cc index 4012a3aa..b46c4920 100644 --- a/absl/container/internal/raw_hash_set_test.cc +++ b/absl/container/internal/raw_hash_set_test.cc @@ -2049,15 +2049,31 @@ TEST(RawHashSamplerTest, Sample) { std::vector<IntTable> tables; for (int i = 0; i < 1000000; ++i) { tables.emplace_back(); + + const bool do_reserve = (i % 10 > 5); + const bool do_rehash = !do_reserve && (i % 10 > 0); + + if (do_reserve) { + // Don't reserve on all tables. + tables.back().reserve(10 * (i % 10)); + } + tables.back().insert(1); tables.back().insert(i % 5); + + if (do_rehash) { + // Rehash some other tables. + tables.back().rehash(10 * (i % 10)); + } } size_t end_size = 0; std::unordered_map<size_t, int> observed_checksums; + std::unordered_map<ssize_t, int> reservations; end_size += sampler.Iterate([&](const HashtablezInfo& info) { if (preexisting_info.count(&info) == 0) { observed_checksums[info.hashes_bitwise_xor.load( std::memory_order_relaxed)]++; + reservations[info.max_reserve.load(std::memory_order_relaxed)]++; } ++end_size; }); @@ -2068,6 +2084,15 @@ TEST(RawHashSamplerTest, Sample) { for (const auto& [_, count] : observed_checksums) { EXPECT_NEAR((100 * count) / static_cast<double>(tables.size()), 0.2, 0.05); } + + EXPECT_EQ(reservations.size(), 10); + for (const auto& [reservation, count] : reservations) { + EXPECT_GE(reservation, 0); + EXPECT_LT(reservation, 100); + + EXPECT_NEAR((100 * count) / static_cast<double>(tables.size()), 0.1, 0.05) + << reservation; + } } #endif // ABSL_INTERNAL_HASHTABLEZ_SAMPLE |