-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.hpp
131 lines (118 loc) · 3.38 KB
/
test.hpp
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
119
120
121
122
123
124
125
126
127
128
129
130
#ifndef __TEST_HPP__
#define __TEST_HPP__
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <vector>
#include <string>
#include <random>
#include <chrono>
class Timer {
std::chrono::steady_clock::time_point _s;
std::chrono::steady_clock::time_point _e;
public:
Timer()
{
Start();
}
inline void Start() {
_s = std::chrono::steady_clock::now();;
}
inline void Stop() {
_e = std::chrono::steady_clock::now();;
}
inline double elapsed() const {
return std::chrono::duration_cast<std::chrono::microseconds>(_e - _s).count()*0.001;
}
inline double elapsed_sec() const {
return std::chrono::duration_cast<std::chrono::milliseconds>(_e - _s).count()*0.001;
}
};
struct Rect {
double x0, x1;
double y0, y1;
};
inline bool Intersect(const Rect& r1, const Rect& r2)
{
return !((r1.x0 > r2.x1) ||
(r1.x1 < r2.x0) ||
(r1.y0 > r2.y1) ||
(r1.y1 < r2.y0));
}
struct Node {
uint64_t id; // 节点ID
std::string url; // 影像路径
Rect box; // 外包框
time_t dtime; // 数据时间
int sat; // 卫星
};
class TestBase {
std::mt19937 mt;
inline double rand_real()
{
return double(mt()) / (mt.max() - mt.min());
}
inline uint32_t rand_uint()
{
return mt();
}
protected:
void resetRand(int seed)
{
mt.seed(seed);
}
void getNextData(Rect& r, time_t& dtime, int& sat)
{
// 生成大小在0.002~0.2度大小的矩形(绝大部分影像的大小)
// 0.002度约为222米,0.2度 22.26千米
// 高与宽的长度差距在上下70%以内
Node n;
r.x0 = -180 + rand_real() * 359.8;
r.y0 = -90 + rand_real() * 179.8;
double w = 0.002 + rand_real() * 0.1998;
double h = w * (1.0 + double(0.01 * (70 - (int)(rand_uint() % 141))));
r.x1 = r.x0 + w;
r.y1 = r.y0 + h;
// 时间控制在1990年1月1日到2019年1月1日
dtime = 631123200 + rand_uint() % 915148800;
// 卫星限制在0-5
sat = rand_uint() % 6;
}
void getQueryArg(Rect& r,time_t& t0,time_t& t1,int& sat)
{
// 查询框在 0.0023~5.625度(约为度网格5~16级)
double w = 0.0023 + rand_real() * 5.625;
r.x0 = -180 + rand_real() * (360.0 - w);
r.y0 = -90 + rand_real() * (180.0 - w);
r.x1 = r.x0 + w;
r.y1 = r.y0 + w;
// 时间控制在1个月(2592000)~5年(155520000)之间
time_t el = 2592000 + (rand_uint() % 152928000);
t0 = 631123200 + (rand_uint() % (915148800-el));
t1 = t0 + el;
// 卫星
sat = rand_uint() % 6;
}
public:
virtual void init(size_t count) = 0;
virtual void insert(size_t count) = 0;
virtual void query(size_t count) = 0;
};
template<typename T>
void TestRun(size_t count)
{
TestBase* p = new T;
Timer t;
p->init(count);
printf("\n\nSSSSSSSSSSSSSSSS----TestRun(insert(%llu))----SSSSSSSSSSSSSSSS\n", count);
t.Start();
p->insert(count);
t.Stop();
printf("\n-----TestRun(insert(%llu)) 耗时%lf-----\n", count, t.elapsed());
printf("\n------------TestRun(query(%llu))-----------\n", count);
t.Start();
p->query(20000);
t.Stop();
printf("\nEEEEEEEEEEEEEEEE----TestRun(query(%llu)) 耗时%lf----EEEEEEEE\n", count, t.elapsed());
}
#endif //!__TEST_HPP__