42 lines
1.3 KiB
C
42 lines
1.3 KiB
C
#include "repetition_tester.c"
|
|
#include "utils.c"
|
|
|
|
static void test_write_to_all_bytes(struct repetitor *repetitor, uint8_t *buffer, uint64_t buffer_size, bool should_alloc) {
|
|
repetitor_clear(repetitor);
|
|
|
|
while (repetitor_repeat(repetitor, 2)) {
|
|
repetitor_start(repetitor);
|
|
alloc_buffer(should_alloc, &buffer, buffer_size);
|
|
|
|
repetitor_measure_start(repetitor);
|
|
for (int i = 0; i < buffer_size; i++) {
|
|
buffer[i] = (uint8_t)i;
|
|
}
|
|
repetitor_measure_stop(repetitor, buffer_size);
|
|
|
|
free_buffer(should_alloc, buffer);
|
|
repetitor_stop(repetitor);
|
|
}
|
|
}
|
|
|
|
int main_test_write_all_bytes() {
|
|
struct repetitor repetitor = {};
|
|
repetitor_init(&repetitor);
|
|
printf("CPU Frequency: %ldHz (~%.2fGHz)\n", repetitor.cpu_freq, (float)repetitor.cpu_freq/(1000*1000*1000));
|
|
|
|
uint64_t byte_count = 4096 * (1024 * 8);
|
|
uint8_t *buffer = malloc(sizeof(uint8_t) * byte_count);
|
|
memset(buffer, 0, byte_count); // Touch memory, so OS would be forced to page in the memory
|
|
|
|
while (repeat_cycle_forever(&repetitor)) {
|
|
test_write_to_all_bytes(&repetitor, buffer, byte_count, false);
|
|
repetitor_print_results_label(&repetitor, "write to all bytes + no malloc");
|
|
|
|
test_write_to_all_bytes(&repetitor, buffer, byte_count, true);
|
|
repetitor_print_results_label(&repetitor, "write to all bytes + malloc");
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|