Yes, you spend a lot of time on hours. When you write ledChange(LOW) , it ledChange(LOW) into an instruction of type CALL (which tells the program counter register to go to the location of the method).
So this will be compiled basically:
- Put
LOW on some register or stack - go to location
ledChange() - Remove
led from memory and put it along with LOW somewhere - go to
digitalWrite() - do whatever is in
digitalWrite() - come back
- come back
Note that the CALL jump involves a lot of stack clutter and takes a lot longer than the usual JMP instruction.
On the other hand, it only does digitalWrite(led,LOW) :
- Remove the
led , LOW from somewhere in the memory and put them somewhere available. - go to
ditigalWrite() - do whatever is in
digitalWrite() - come back
I'm not quite sure how the arguments are passed in the corresponding compiled code, this is probably part of the call. Also note that compilers are changing, and some are smarter than others.
You can see that your encapsulation of the function caused the program to take more clock cycles each time you run it. However, this is not worth optimizing; I do not see a large capacity in such encapsulation to slow down Arduino. In addition, as I already mentioned, some compilers optimize such things.
This has nothing to do with the function being void . If it was an int function, it would be a little slower, since saving an int before returning includes an MV operation or a stack (forgot that).
source share