From 3e38d5561d3e2e60f79ec5387f167bb12170c0f9 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Tue, 27 Apr 2021 12:45:54 +0200 Subject: Testing the performance of memcpy vs dma_copy routines --- src/main.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/main.c b/src/main.c index efd460f..88bc3b8 100644 --- a/src/main.c +++ b/src/main.c @@ -40,18 +40,24 @@ int main(void) { COLOR_BLUE, COLOR_BLUE, }; - // These should be equivalent here, but remember that the dma_copy and - // dma_fill functions will always work on U32 chunks. - // - // memcpy(&PAL_BUFFER_SPRITES[0], colors, 16 * sizeof(Color)); - // dma_copy(&PAL_BUFFER_SPRITES[0], colors, 16 * sizeof(Color), 3); - u32 color = COLOR_RED | COLOR_RED << 16; - dma_fill(&PAL_BUFFER_SPRITES[0], color, 16 * sizeof(Color), 3); + size_t n_iter = 10000; + profile_start(); + for (size_t i = 0; i < n_iter; ++i) { + dma_copy(&PAL_BUFFER_SPRITES[0], colors, 16 * sizeof(Color), 3); + } + u32 dma_copy_perf = profile_stop(); + + profile_start(); + for (size_t i = 0; i < n_iter; ++i) { + memcpy(&PAL_BUFFER_SPRITES[0], colors, 16 * sizeof(Color)); + } + u32 memcpy_perf = profile_stop(); // Initialize text engine. - // txt_init(0, COLOR_RED, 0); - // txt_printf("TEST"); + txt_init(0, COLOR_RED, 0); + txt_printf("N. cycles memcpy: %d\n", memcpy_perf); + txt_printf("N. cycles dma_copy: %d\n", dma_copy_perf); int frame_counter = 0; while(true) { @@ -59,7 +65,7 @@ int main(void) { poll_keys(); frame_counter++; - update_button_sprites(); + // update_button_sprites(); }; return 0; -- cgit v1.2.1