MCPcopy Create free account
hub / github.com/apache/brpc / perf_insert_erase

Function perf_insert_erase

test/flat_map_unittest.cpp:1211–1378  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1209
1210template <typename T>
1211void perf_insert_erase(bool random, const T& value) {
1212 size_t nkeys[] = { 100, 1000, 10000 };
1213 const size_t NPASS = ARRAY_SIZE(nkeys);
1214
1215 std::vector<uint64_t> keys;
1216 butil::FlatMap<uint64_t, T> id_map;
1217 butil::MultiFlatMap<uint64_t, T> multi_id_map;
1218 std::map<uint64_t, T> std_map;
1219 butil::PooledMap<uint64_t, T> pooled_map;
1220 std::unordered_map<uint64_t, T> std_unordered_map;
1221 std::unordered_multimap<uint64_t, T> std_unordered_multimap;
1222 butil::hash_map<uint64_t, T> hash_map;
1223 butil::Timer id_tm, multi_id_tm, std_tm, pooled_tm,
1224 std_unordered_tm, std_unordered_multi_tm, hash_tm;
1225
1226 size_t max_nkeys = 0;
1227 for (size_t i = 0; i < NPASS; ++i) {
1228 max_nkeys = std::max(max_nkeys, nkeys[i]);
1229 }
1230 id_map.init((size_t)(nkeys[NPASS-1] * 1.5));
1231 multi_id_map.init((size_t)(nkeys[NPASS-1] * 1.5));
1232
1233 // Make DS hot
1234 for (size_t i = 0; i < max_nkeys; ++i) {
1235 id_map[i] = value;
1236 std_map[i] = value;
1237 pooled_map[i] = value;
1238 hash_map[i] = value;
1239 }
1240 id_map.clear();
1241 std_map.clear();
1242 pooled_map.clear();
1243 std_unordered_map.clear();
1244 std_unordered_multimap.clear();
1245 hash_map.clear();
1246
1247 LOG(INFO) << "[ value = " << sizeof(T) << " bytes ]";
1248 for (size_t pass = 0; pass < NPASS; ++pass) {
1249 int start = rand();
1250 keys.clear();
1251 for (size_t i = 0; i < nkeys[pass]; ++i) {
1252 keys.push_back(start + i);
1253 }
1254
1255 if (random) {
1256 random_shuffle(keys.begin(), keys.end());
1257 }
1258
1259 id_map.clear();
1260 id_tm.start();
1261 for (size_t i = 0; i < keys.size(); ++i) {
1262 id_map[keys[i]] = value;
1263 }
1264 id_tm.stop();
1265
1266 multi_id_map.clear();
1267 multi_id_tm.start();
1268 for (size_t i = 0; i < keys.size(); ++i) {

Callers

nothing calls this directly

Calls 11

n_elapsedMethod · 0.80
initMethod · 0.45
clearMethod · 0.45
push_backMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
startMethod · 0.45
sizeMethod · 0.45
stopMethod · 0.45
insertMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected