-
Notifications
You must be signed in to change notification settings - Fork 1
/
performance.cpp
224 lines (184 loc) · 4.55 KB
/
performance.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
//
// Created by LSC on 2020/4/5.
//
#include "LSM_tree.h"
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <time.h>
#define PUT_TEST 1024*15
using namespace std;
void get_test()
{
LSM_tree store;
for(int i=0;i<1024*32;i++)
{
store.put(i,std::string(i+1, 's'));
if(i%1024==0)
{
unsigned int test=0;
double all_time=0;
for(int m=0;m<1024*2;m++)
{
clock_t start = clock();
store.get(m);
clock_t ends = clock();
test++;
all_time+=(double)(ends - start);
}
cout<<i<<" "<<(all_time/test)/ CLOCKS_PER_SEC<<endl;
}
}
unsigned int test=0;
double all_time=0;
for(int i=0;i<1024*2;i++)
{
clock_t start = clock();
store.get(i);
clock_t ends = clock();
test++;
all_time+=(double)(ends - start);
}
cout<<test<<" "<<all_time<<" "<<(all_time/test)/ CLOCKS_PER_SEC<<endl;
}
void delete_test()
{
LSM_tree store;
for(int i=0;i<1024*12;i++)
{
store.put(i,std::string(i+1, 's'));
}
unsigned int test=0;
double all_time=0;
for(int i=0;i<1024*2;i++)
{
//uint64_t p=rand();
store.compact= false;
clock_t start = clock();
store.del(i);
clock_t ends = clock();
if(!store.compact)
{
test++;
all_time+=(double)(ends - start);
}
}
cout<<test<<" "<<all_time<<" "<<(all_time/test)/ CLOCKS_PER_SEC<<endl;
}
void put_test()
{
// for(int k=50;k<=1000;k+=50)
// {
// LSM_tree store;
// unsigned int test=0;
// double all_time=0;
//
// for(int i=0;i<k;i++)
// {
// store.compact= false;
// uint64_t p=rand();
//
//
// clock_t start = clock();
// store.put(p,std::string(p+1, 's'));
// clock_t ends = clock();
//
// //只有没有发生合并的时候才记录
// if(!store.compact)
// {
// test++;
// all_time+=(double)(ends - start)/ CLOCKS_PER_SEC;
// }
// }
//
// cout<<test<<" "<<all_time<<" "<<all_time/test<<endl;
// }
LSM_tree store;
uint64_t test=0,i=0;
double all_time=0;
double old_time=0;
int count=0;
clock_t start = clock();
while(i!=1024*16)
{
store.compact=false;
int p=rand();
int q=rand();
store.put(p,std::string(q+1, 's'));
clock_t ends = clock();
double now=(double)(ends-start)/CLOCKS_PER_SEC;
//只有没有发生合并的时候才记录
// if(store.compact)
// {
// cout<<"!"<<endl;
//
// }
i++;
//test++;
//all_time+=(double)(ends - start)/ CLOCKS_PER_SEC;
count++;
if(now-old_time>0.005)
{
cout<<now<<" "<<count/(now-old_time)<<endl;
old_time=now;
count=0;
}
}
// cout<<test<<" "<<(all_time/test)/ CLOCKS_PER_SEC<<endl;
// for(int k=1024;k<PUT_TEST;k+=4048)
// {
// LSM_tree store;
// unsigned int test=0;
// double all_time=0;
//
// for(int i=0;i<k;i++)
// {
// store.compact= false;
// uint64_t p=rand();
//
//
// clock_t start = clock();
// store.put(p,std::string(p+1, 's'));
// clock_t ends = clock();
//
// //只有没有发生合并的时候才记录
// if(!store.compact)
// {
// test++;
// all_time+=(double)(ends - start)/ CLOCKS_PER_SEC;
// }
// }
//
// cout<<test<<" "<<all_time<<" "<<all_time/test<<endl;
// }
// LSM_tree store;
// unsigned int test=0;
// double all_time=0;
// for(int i=0;i<1024*16;i++)
// {
// store.compact= false;
// uint64_t p=rand();
//
// cout<<i<<" "<<p<<endl;
//
// clock_t start = clock();
// store.put(p,std::string(p+1, 's'));
// clock_t ends = clock();
//
// //只有没有发生合并的时候才记录
// if(!store.compact)
// {
// test++;
// all_time+=(double)(ends - start)/ CLOCKS_PER_SEC;
// }
// }
//
// cout<<test<<" "<<all_time<<" "<<all_time/test<<endl;
}
int main()
{
// srand(time(NULL));
put_test();
//get_test();
//delete_test();
}