-
Notifications
You must be signed in to change notification settings - Fork 0
/
perf-test.c
139 lines (106 loc) · 3.2 KB
/
perf-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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include "bmem.h"
#define ALLOC_CNT 10240000
static void test_interleaved_fashion()
{
clock_t begin, end;
double time_spent;
int **a = malloc(sizeof(int *) * ALLOC_CNT);
/* normal malloc and free */
begin = clock();
for (uint32_t i = 0; i < ALLOC_CNT; i++) {
a[i] = malloc(sizeof(int));
free(a[i]);
}
end = clock();
time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
printf("Normal interleaved fashion: Time spent: %f seconds\n", time_spent);
/* Bmem */
begin = clock();
bm_context_t *ctx = bm_context_register(8, 1024);
for (uint32_t i = 0; i < ALLOC_CNT; i++) {
a[i] = bm_malloc(ctx, sizeof(int));
bm_free_s(a[i], sizeof(int));
}
bm_context_destroy(ctx);
end = clock();
time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
printf("Bmem interleaved fashion: Time spent: %f seconds\n", time_spent);
free(a);
}
static void test_bulk_fashion()
{
clock_t begin, end;
double time_spent;
int **a = malloc(sizeof(int *) * ALLOC_CNT);
/* normal malloc and free */
begin = clock();
for (uint32_t i = 0; i < ALLOC_CNT; i++) {
a[i] = malloc(sizeof(int));
}
for (uint32_t i = 0; i < ALLOC_CNT; i++) {
free(a[i]);
}
end = clock();
time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
printf("Normal bulk fashion: Time spent: %f seconds\n", time_spent);
/* Bmem */
begin = clock();
bm_context_t *ctx = bm_context_register(8, ALLOC_CNT/4);
for (uint32_t i = 0; i < ALLOC_CNT; i++) {
a[i] = bm_malloc(ctx, sizeof(int));
}
for (uint32_t i = 0; i < ALLOC_CNT; i++) {
bm_free_s(a[i], sizeof(int));
}
bm_context_destroy(ctx);
end = clock();
time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
printf("Bmem bulk fashion: Time spent: %f seconds\n", time_spent);
free(a);
}
static void test_bulk_fashion2()
{
clock_t begin, end;
double time_spent;
int **a = malloc(sizeof(int *) * ALLOC_CNT);
double **b = malloc(sizeof(double *) * ALLOC_CNT);
/* normal malloc and free */
begin = clock();
for (uint32_t i = 0; i < ALLOC_CNT; i++) {
a[i] = malloc(sizeof(int));
b[i] = malloc(sizeof(double));
}
for (uint32_t i = 0; i < ALLOC_CNT; i++) {
free(a[i]);
free(b[i]);
}
end = clock();
time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
printf("Normal bulk fashion2: Time spent: %f seconds\n", time_spent);
/* Bmem */
begin = clock();
bm_context_t *ctx = bm_context_register(8, ALLOC_CNT/4);
for (uint32_t i = 0; i < ALLOC_CNT; i++) {
a[i] = bm_malloc(ctx, sizeof(int));
b[i] = bm_malloc(ctx, sizeof(double));
}
for (uint32_t i = 0; i < ALLOC_CNT; i++) {
bm_free_s(a[i], sizeof(int));
bm_free_s(b[i], sizeof(double));
}
bm_context_destroy(ctx);
end = clock();
time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
printf("Bmem bulk fashion2: Time spent: %f seconds\n", time_spent);
free(a);
}
int main()
{
test_interleaved_fashion();
test_bulk_fashion();
test_bulk_fashion2();
return 0;
}