-
Notifications
You must be signed in to change notification settings - Fork 4
/
eredis_benchmark.c
78 lines (60 loc) · 1.71 KB
/
eredis_benchmark.c
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
/*
* A simple benchmark for the eredis library.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>
#include <assert.h>
#include "redis/src/eredis.h"
static unsigned long get_mstime(void)
{
struct timeval tv;
long long t;
gettimeofday(&tv, NULL);
t = ((unsigned long) tv.tv_sec) * 1000;
t += tv.tv_usec/1000;
return t;
}
void run_benchmark(const char *name, int argc, const char **argv, unsigned long count, int reuse_req)
{
eredis_client_t *c;
unsigned long i;
unsigned long stime, etime;
int ret;
c = eredis_create_client();
assert(c != NULL);
printf("%-30s : ...", name);
stime = get_mstime();
for (i = 0; i < count; i++) {
if (!i || !reuse_req) {
ret = eredis_prepare_request(c, argc, argv, NULL);
assert(ret == 0);
}
ret = eredis_execute(c);
assert(ret == 0);
/* Drain response */
int len;
while (eredis_read_reply_chunk(c, &len) != NULL);
}
etime = get_mstime();
printf("\b\b\b%lu ops/sec\n", count / (etime - stime) * 1000);
eredis_free_client(c);
}
int main(int argc, char *argv[])
{
int ret = eredis_init();
assert(ret == 0);
setvbuf(stdout, NULL, _IONBF, 0);
static const char *cmd_set[] = {
"SET", "mykey", "myvalue"
};
run_benchmark("SET command, reused query", 3, cmd_set, 1000000, 1);
run_benchmark("SET command, regenerated query", 3, cmd_set, 1000000, 0);
static const char *cmd_get[] = {
"GET", "mykey"
};
run_benchmark("GET command, reused query", 2, cmd_get, 1000000, 1);
run_benchmark("GET command, regenerated query", 2, cmd_get, 1000000, 0);
exit(0);
}