Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ dkms.conf
# Perf
bench

# Test
tests

# cmake output dir
out/*

Expand Down
68 changes: 34 additions & 34 deletions bench.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,52 +19,52 @@ double test_malloc_firstfit(size_t alloc_size);
void *freeing_callback(void *ctx, void *addr, size_t slot_size, size_t allocated);

int main() {
setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stdout, NULL, _IONBF, 0);

size_t arena_size = 1 << 30;
unsigned char *buddy_buf = (unsigned char *) malloc(buddy_sizeof_alignment(arena_size, 64));
unsigned char *data_buf = (unsigned char *) malloc(arena_size);
struct buddy *buddy = buddy_init_alignment(buddy_buf, data_buf, arena_size, 64);
size_t arena_size = 1 << 30;
unsigned char *buddy_buf = (unsigned char *) malloc(buddy_sizeof_alignment(arena_size, 64));
unsigned char *data_buf = (unsigned char *) malloc(arena_size);
struct buddy *buddy = buddy_init_alignment(buddy_buf, data_buf, arena_size, 64);

double total = 0;
for (size_t i = 0; i <= 6; i++) {
total += test_malloc(buddy, 64 << i);
total += test_malloc(buddy, 64 << i);
total += test_malloc(buddy, 64 << i);
}
printf("Total malloc runtime was %f seconds.\n\n", total);
double total = 0;
for (size_t i = 0; i <= 6; i++) {
total += test_malloc(buddy, 64 << i);
total += test_malloc(buddy, 64 << i);
total += test_malloc(buddy, 64 << i);
}
printf("Total malloc runtime was %f seconds.\n\n", total);

free(data_buf);
free(buddy_buf);
free(data_buf);
free(buddy_buf);
}

double test_malloc(struct buddy *buddy, size_t alloc_size) {
printf("Starting test with alloc size [%zu].\n", alloc_size);
time_t start_time = time(NULL);
printf("Starting test with alloc size [%zu].\n", alloc_size);
time_t start_time = time(NULL);

while (buddy_malloc(buddy, alloc_size)) {
// fill it up
}
time_t alloc_time = time(NULL);
while (buddy_malloc(buddy, alloc_size)) {
// fill it up
}
time_t alloc_time = time(NULL);

assert(buddy_is_full(buddy));
assert(buddy_is_full(buddy));

buddy_walk(buddy, freeing_callback, buddy);
assert(buddy_is_empty(buddy));
buddy_walk(buddy, freeing_callback, buddy);
assert(buddy_is_empty(buddy));

time_t end_time = time(NULL);
double delta = difftime(end_time, start_time);
printf("Test took %.f seconds in total. Allocation: %.f freeing: %.f\n", delta,
difftime(alloc_time, start_time), difftime(end_time, alloc_time));
time_t end_time = time(NULL);
double delta = difftime(end_time, start_time);
printf("Test took %.f seconds in total. Allocation: %.f freeing: %.f\n", delta,
difftime(alloc_time, start_time), difftime(end_time, alloc_time));

return delta;
return delta;
}

void *freeing_callback(void *ctx, void *addr, size_t slot_size, size_t allocated) {
if (! allocated) {
return NULL;
}
struct buddy *buddy = (struct buddy*) ctx;
buddy_free(buddy, addr);
return NULL;
if (! allocated) {
return NULL;
}
struct buddy *buddy = (struct buddy*) ctx;
buddy_free(buddy, addr);
return NULL;
}
Loading
Loading