c++ - Optimizing subroutine with memcmp, memcpy -


i wonder if there optimizations (something more efficient memcmp/memcpy maybe using loop or breaking down fast assembly instructions) can done subroutine. num_bytes constant value (always = 18):

void ledsmoothwrite(uint8_t ledtarget[]) {        // if new target different, set new target     if(memcmp(target_arr, ledtarget, num_bytes)) memcpy(target_arr, ledtarget, num_bytes);      // obtain equality     for(uint8_t = 0; < num_bytes; i++)     {         if(rgb_arr[i] < target_arr[i]) rgb_arr[i]++;         else if(rgb_arr[i] > target_arr[i]) rgb_arr[i]--;     }     render(); } 

this subroutine smoothly setting led colors might called several hundred times per second. loop() function increases in run time takes more time each led desired values.

any appreciated. thank in advance!

check documentation on many compilers memcmp() , memcpy() implemented efficient machine code instructions. may (for practical purposes) fast gets.

try not doing comparison. depending on probability ranges equal doing comparison (if different) doing copy may not net win.

however best solution not perform copy @ all!

if possible read out of ledtarget.

it's not clear you're doing animations perform 'double buffering' avoid copying big states around place. if you're working concurrently write 1 buffer while reading , on next cycle write other buffer , read first.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -