-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest.cpp
41 lines (37 loc) · 1.07 KB
/
test.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
#include "Transport.h"
#include <sys/time.h>
double microtime() {
struct timeval now;
gettimeofday(&now, NULL);
double ret = now.tv_sec + now.tv_usec / 1000.0 / 1000.0;
return ret;
}
int main(int argc, char** argv) {
// std::string buf = " *2\r\n$1\na\n$2\r\nbc\r\n ";
// redis::Message msg;
// int n = msg.Decode(buf);
// printf("%d\n%s\n", n, msg.Encode().c_str());
redis::Transport xport;
xport.Start("127.0.0.1", 6379);
double stime = microtime();
int count = 0;
while (1) {
redis::Message msg = xport.Recv();
// printf("req from %d\n", msg.ClientId());
redis::Response resp(msg.ClientId());
xport.Send(resp);
count ++;
if(count % 100000 == 0){
double etime = microtime();
double ts = etime - stime;
if(ts == 0){
ts = 1;
}
double qps = 100000.0 / ts;
printf("qps: %.0f\n", qps);
stime = etime;
}
}
getchar();
return 0;
}