forked from emilk/ram_bench
-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark_pmdk.c
106 lines (81 loc) · 1.99 KB
/
benchmark_pmdk.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
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
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include "libpmemobj.h"
typedef struct Node Node;
typedef uint64_t Int;
PMEMobjpool *pm_pool;
struct Node {
Int payload;
Int payload1;
Int payload2;
Int payload3;
Int payload4;
Int payload5;
Int payload6;
Node* next;
};
void random_shuffle(Node** list, Int N)
{
for (Int i=0; i<N-1; ++i) {
Int swap_ix = i + rand() % (N-i);
Node* tmp = list[swap_ix];
list[swap_ix] = list[i];
list[i] = tmp;
}
}
double benchmark_pmemobj_tx_zalloc(Int N) {
PMEMoid oid;
double ns;
Int start = clock();
for(Int i=0;i<N;i++) {
TX_BEGIN(pm_pool) {
// printf("Running");
oid = pmemobj_tx_zalloc(sizeof(Node), 0);
} TX_END
}
Int dur = clock() - start;
ns = 1e9 * dur / CLOCKS_PER_SEC;
return ns / N;
}
double benchmark_pmemobj_zalloc(Int N) {
PMEMoid oid;
double ns;
Int start = clock();
for(Int i=0;i<N;i++) {
// printf("Running");
pmemobj_zalloc(pm_pool, &oid ,sizeof(Node), 0);
}
Int dur = clock() - start;
ns = 1e9 * dur / CLOCKS_PER_SEC;
return ns / N;
}
double benchmark_empty_transaction(Int N) {
PMEMoid oid;
double ns;
Int start = clock();
for(Int i=0;i<N;i++) {
TX_BEGIN(pm_pool) {
// No statements
// printf("Running");
} TX_END
}
Int dur = clock() - start;
ns = 1e9 * dur / CLOCKS_PER_SEC;
return ns / N;
}
int main() {
long long int GB = 1024*1024*1024;
long long int pmem_size = GB*1;
long long int N;
pm_pool = pmemobj_create("/mnt/mem/a.pm", "store.db", pmem_size+20, 0666);
// N = pmem_size/ sizeof(Node);
N = 1000;
double ans;
ans = benchmark_empty_transaction(N);
// ans = benchmark_pmemobj_tx_zalloc(N);
// ans = benchmark_pmemobj_zalloc(N);
printf("The average latency for %lu bytes and %lld elements is %f\n", sizeof(Node), N, ans);
}