I thought this was odd that memset took *exactly* the same amount of time as my loop. Both were 615 us. Isn't memset optimized? I guess it was implemented as just a loop as well? (FWIW, screen_buf is declared as: char screen_buf[320][240*2].)
With for loop:
With memset:
With for loop:
Code:
uint32_t time_start, time_end, time_taken; time_start = time_us_32(); for (r = 0; r < SCREEN_HEIGHT; r++) { for (c = 0; c < SCREEN_WIDTH*2; c++) { screen_buf[r][c] = 0x00; } } time_end = time_us_32(); time_taken = time_end - time_start; printf("1: %lu\n", time_taken);
Code:
uint32_t time_start, time_end, time_taken; time_start = time_us_32(); memset(screen_buf, 0, sizeof(screen_buf)); time_end = time_us_32(); time_taken = time_end - time_start; printf("1: %lu\n", time_taken);
Statistics: Posted by Mike**K — Sat Feb 22, 2025 2:19 am — Replies 4 — Views 91