Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Side by Side Diff: base/trace_event/memory_usage_estimator_unittest.cc

Issue 2676043002: [memory-infra] Add EstimateMemoryUsage() for deque and friends. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/trace_event/memory_usage_estimator.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/trace_event/memory_usage_estimator.h" 5 #include "base/trace_event/memory_usage_estimator.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 } 218 }
219 219
220 TEST(EstimateMemoryUsageTest, UnorderedMultiMap) { 220 TEST(EstimateMemoryUsageTest, UnorderedMultiMap) {
221 std::unordered_multimap<Data, short, Data::Hasher> map; 221 std::unordered_multimap<Data, short, Data::Hasher> map;
222 for (int i = 0; i != 1000; ++i) { 222 for (int i = 0; i != 1000; ++i) {
223 map.insert({Data(i), static_cast<short>(i)}); 223 map.insert({Data(i), static_cast<short>(i)});
224 } 224 }
225 EXPECT_EQ_32_64(515540u, 531580u, EstimateMemoryUsage(map)); 225 EXPECT_EQ_32_64(515540u, 531580u, EstimateMemoryUsage(map));
226 } 226 }
227 227
228 TEST(EstimateMemoryUsageTest, Deque) {
229 std::deque<Data> deque;
230
231 // Pick a large value so that platform-specific accounting
232 // for deque's blocks is small compared to usage of all items.
233 constexpr size_t kDataSize = 100000;
234 for (int i = 0; i != 1500; ++i) {
235 deque.push_back(Data(kDataSize));
236 }
237
238 // Compare against a reasonable minimum (i.e. no overhead).
239 size_t min_expected_usage = deque.size() * (sizeof(Data) + kDataSize);
240 EXPECT_LE(min_expected_usage, EstimateMemoryUsage(deque));
241 }
242
228 } // namespace trace_event 243 } // namespace trace_event
229 } // namespace base 244 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event/memory_usage_estimator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698