Hello,
Which of the two codes is more efficient? For obvious reasons, using the for loop is easier but I think I heard addition can be pretty fast. I am just trying to add together the elements of a previously defined array and I am concerned about speed and efficiency. I will be using it for real time control on a microcontroller later.
Thanks.
The loop is more efficient (programmer efficient).
All these are more or less equally efficient (machine efficient).
The optimiser knows how to unroll these loops, and would use that knowledge to good effect:
Thank you very much @qwertykeyboard @JLBorges and @Enoizat.
I appreciate your kind guidance. I guess I will go ahead with the loop.
Kind regards.
David.
adding up 9 values no matter what method shouldnt be your bottleneck, are you still having performance issues? If so, something else is probably behind it, what else are you doing around the code that you are timing?