-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbench.c
61 lines (56 loc) · 1.64 KB
/
bench.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
#include <stdlib.h>
#include <stdio.h>
#include "queue.h"
#include <libgen.h>
#include <string.h>
#include <stdint.h>
#include <time.h>
#define LOG_ERROR(cmd) logError(#cmd, __LINE__, cmd)
static void logError(const char * cmd, int line, int rtn) {
if (LIBQUEUE_SUCCESS != rtn) {
printf("ERROR: cmd");
}
}
int main(int argc, char **argv) {
size_t bufSize= 5*100*1024*1024;
size_t blockSize= 1024;
struct Queue *q;
char template[] = "/tmp/qtest_XXXXXX";
if (NULL == mkdtemp(template)) {
puts("failed to create temp dir for running tests");
return 1;
}
q = queue_open_with_options(template,"maxBinLogSize", 10000000, NULL);
if(0 == queue_is_opened(q)) {
fprintf(stderr,"Failed to open the queue:%s", queue_get_last_error(q));
LOG_ERROR(queue_close(q));
return EXIT_FAILURE;
}
char *buf = malloc (bufSize);
memset(buf,'f',bufSize);
time_t start = time(NULL);
intptr_t offset=0;
for(; offset < bufSize; offset +=blockSize) {
struct QueueData qd;
qd.vlen = blockSize;
qd.v = buf + offset;
LOG_ERROR(queue_push(q, &qd));
}
time_t end= time(NULL);
time_t difft = end-start;
printf("it took %lu to push %lu(%g) in %lu(%g) blocks\n", (unsigned long )difft, bufSize,bufSize/ (double) difft, blockSize, blockSize/(double)difft);
start = time(NULL);
offset=0;
for(; offset < bufSize; offset +=blockSize) {
struct QueueData qd;
LOG_ERROR(queue_pop(q, &qd));
if (qd.v)
free(qd.v);
}
end= time(NULL);
difft = end-start;
printf("it took %lu to pop %lu(%g) in %lu(%g) blocks\n", (unsigned long) difft,bufSize,bufSize/ (double) difft, blockSize, blockSize/(double)difft);
LOG_ERROR(queue_close(q));
free(buf);
return 0;
}