forked from sylar-yin/sylar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_dict.cc
51 lines (44 loc) · 1.16 KB
/
test_dict.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "sylar/sylar.h"
#include "sylar/ds/dict.h"
static sylar::Logger::ptr g_logger = SYLAR_LOG_ROOT();
struct PidVid {
PidVid(uint32_t p = 0, uint32_t v = 0)
:pid(p), vid(v) {}
uint32_t pid;
uint32_t vid;
bool operator<(const PidVid& o) const {
return memcmp(this, &o, sizeof(o)) < 0;
}
};
void gen() {
sylar::ds::Dict<int, PidVid> tmp;
for(int i = 0; i < 500000; ++i) {
int32_t len = rand() % 10 + 5;
int k = rand();
std::vector<PidVid> pvs;
for(int n = 0; n < len; ++n) {
pvs.push_back(PidVid(rand(), rand()));
}
tmp.insert(k, pvs.data(), pvs.size());
}
std::ofstream ofs("./dict.data");
tmp.writeTo(ofs);
}
void test() {
for(int i = 0; i < 10000; ++i) {
SYLAR_LOG_INFO(g_logger) << "i=" << i;
std::ifstream ifs("./dict.data");
sylar::ds::Dict<int, PidVid> tmp;
if(!tmp.readFrom(ifs)) {
SYLAR_LOG_INFO(g_logger) << "error";
}
if(i % 100 == 0) {
SYLAR_LOG_INFO(g_logger) << "over..." << (i + 1);
}
}
}
int main(int argc, char** argv) {
gen();
test();
return 0;
}