-
Notifications
You must be signed in to change notification settings - Fork 5
/
rolla_test.c
70 lines (59 loc) · 1.53 KB
/
rolla_test.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
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <unistd.h>
#include "rolla.h"
#define COUNT 1000000
#define DCOUNT ((double)COUNT)
double doublenow() {
struct timeval tv;
gettimeofday(&tv, NULL);
return (double)tv.tv_sec
+ (((double)tv.tv_usec) / 1000000.0);
}
int main() {
double start;
printf("-- load --\n");
start = doublenow();
rolla *db = rolla_create("db");
printf("load took %.3f\n",
doublenow() - start);
int i;
char buf2[8] = {0};
printf("-- write --\n");
start = doublenow();
for (i=0; i < COUNT; i++) {
snprintf(buf2, 8, "%d", i % 2 ? i : 4);
rolla_set(db, buf2, (uint8_t *)buf2, 8);
}
double final;
final = doublenow();
printf("write took %.3f (%.3f/s)\n",
final - start, DCOUNT / (final - start));
sleep(3);
printf("-- read --\n");
uint32_t sz;
start = doublenow();
for (i=0; i < COUNT; i++) {
snprintf(buf2, 8, "%d", i % 2 ? i : 4);
char *p = (char *)rolla_get(db, buf2, &sz);
assert(p && !strcmp(buf2, p));
free(p);
if (i % 100000 == 0)
printf("%d\n", i);
}
final = doublenow();
printf("read took %.3f (%.3f/s)\n",
final - start, DCOUNT / (final - start));
snprintf(buf2, 8, "%d", 4);
char *p = (char *)rolla_get(db, buf2, &sz);
assert(p);
free(p);
rolla_del(db, buf2);
p = (char *)rolla_get(db, buf2, &sz);
assert(!p);
rolla_close(db, 1);
return 0;
}