diff --git a/src/main.c b/src/main.c index 781f63d..f5b551b 100644 --- a/src/main.c +++ b/src/main.c @@ -12,6 +12,7 @@ #include "main_write_bytes_asm.c" #include "main_write_all_bytes.c" #include "main_malloc_read.c" +#include "main_write_backward.c" int main(int argc, char **argv) { if (argc < 2) { @@ -25,6 +26,8 @@ int main(int argc, char **argv) { return main_test_write_bytes_asm(); } else if (!strncmp(test_name, "write_all_bytes", sizeof("write_bytes"))) { return main_test_write_all_bytes(); + } else if (!strncmp(test_name, "write_backward", sizeof("write_backward"))) { + return main_test_write_backward(); } else if (!strncmp(test_name, "read_file", sizeof("read_file"))) { if (argc < 3) { printf("Usage: %s read_file \n", argv[0]); diff --git a/src/main_write_all_bytes.c b/src/main_write_all_bytes.c index fdbfa6d..0a13861 100644 --- a/src/main_write_all_bytes.c +++ b/src/main_write_all_bytes.c @@ -20,7 +20,6 @@ static void test_write_to_all_bytes(struct repetitor *repetitor, uint8_t *buffer } 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)); diff --git a/src/main_write_backward.c b/src/main_write_backward.c new file mode 100644 index 0000000..cdca37e --- /dev/null +++ b/src/main_write_backward.c @@ -0,0 +1,41 @@ +#include "repetition_tester.c" + +int main_test_write_backward() { + 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); + + while (repeat_cycle_times(&repetitor, 3)) { + repetitor_clear(&repetitor); + while (repetitor_repeat(&repetitor, 2)) { + repetitor_start(&repetitor); + uint8_t *buffer = malloc(sizeof(uint8_t) * byte_count); + repetitor_measure_start(&repetitor); + for (int i = 0; i < byte_count; i++) { + buffer[i] = (uint8_t)i; + } + repetitor_measure_stop(&repetitor, byte_count); + free(buffer); + repetitor_stop(&repetitor); + } + repetitor_print_results_label(&repetitor, "write forward"); + + repetitor_clear(&repetitor); + while (repetitor_repeat(&repetitor, 2)) { + repetitor_start(&repetitor); + uint8_t *buffer = malloc(sizeof(uint8_t) * byte_count); + repetitor_measure_start(&repetitor); + for (int i = 0; i < byte_count; i++) { + buffer[byte_count - i - 1] = (uint8_t)i; + } + repetitor_measure_stop(&repetitor, byte_count); + free(buffer); + repetitor_stop(&repetitor); + } + repetitor_print_results_label(&repetitor, "write backward"); + } + + return 0; +}