-
Notifications
You must be signed in to change notification settings - Fork 0
/
testiter.cpp
118 lines (105 loc) · 3.25 KB
/
testiter.cpp
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include "test.hpp"
const int inserseed = 9999;
const int queryseed = 8888;
class TestIter :public TestBase {
std::vector<Node> data;
public:
void init(size_t count)
{
data.reserve(count);
}
void insert(size_t count)
{
resetRand(inserseed);
Timer t;
double zsj = 0;
for (size_t i = 0; i < count; ++i) {
// 获取节点数据
Node n;
getNextData(n.box, n.dtime, n.sat);
n.url = std::to_string(i);
n.id = i;
// 插入计时
t.Start();
data.emplace_back(n);
t.Stop();
zsj += t.elapsed();
}
printf(" 插入 %llu 总耗时:%lf 毫秒\n", count, zsj);
}
void query(size_t count)
{
resetRand(queryseed);
Timer t;
double zsj = 0;
for (size_t i = 0; i < count; ++i) {
// 获取查询条件
Rect r;
time_t t0, t1;
int sat;
getQueryArg(r, t0, t1, sat);
// 查询计时
t.Start();
std::vector<size_t> result;
for (size_t ii = 0; ii < data.size(); ++ii) {
Node& n = data[ii];
if (Intersect(r, n.box)) {
result.push_back(n.id);
}
}
t.Stop();
zsj += t.elapsed();
// 输出中间那次的查询条件和结果
if (i == count / 2) {
printf(" 查询条件:box[(%lf,%lf)-(%lf,%lf)],%lld<=dtime<=%lld,sat=%d\n 查询结果(仅输出ID):",
r.x0, r.y0, r.x1, r.y1, t0, t1, sat);
for (auto& id : result) {
printf("%llu,", id);
}
puts("\n");
}
}
printf(" 查询(仅范围) %llu 总耗时:%lf 毫秒\n", count, zsj);
resetRand(queryseed);
zsj = 0;
for (size_t i = 0; i < count; ++i) {
// 获取查询条件
Rect r;
time_t t0, t1;
int sat;
getQueryArg(r, t0, t1, sat);
// 查询计时
t.Start();
std::vector<size_t> result;
for (size_t ii = 0; ii < data.size(); ++ii) {
Node& n = data[ii];
if (Intersect(r, n.box) &&
(n.dtime <= t1 && n.dtime >= t0) &&
n.sat == sat) {
result.push_back(n.id);
}
}
t.Stop();
zsj += t.elapsed();
// 输出中间那次的查询条件和结果
if (i == count / 2) {
printf(" 查询条件:box[(%lf,%lf)-(%lf,%lf)],%lld<=dtime<=%lld,sat=%d\n 查询结果(仅输出ID):",
r.x0, r.y0, r.x1, r.y1, t0, t1, sat);
for (auto& id : result) {
printf("%llu,", id);
}
puts("\n");
}
}
printf(" 查询(全条件) %llu 总耗时:%lf 毫秒\n", count, zsj);
}
};
int main()
{
TestRun<TestIter>(10000);
TestRun<TestIter>(50000);
TestRun<TestIter>(100000);
TestRun<TestIter>(200000);
// TestRun<TestIter>(1000000);
return 0;
}