Question about processing

Good Night Friends..
What Is More Fast, Check The Variable And Write A Value One Time, Or Write Every Time?
Ho I Can See, How Many Cicles Is Needed To Run My Program? Tks...

[EDIT]
Sorry for my english and for my phone... which is faster: read a variable, verify and write only one time on the loop, or write every time? ex:

loop{
if (variable != 0)
    variable = 0;
}

or

loop{
variable = 0;
}

I saw somewhere, a software, but i dont remenber, to program arduino and when you compile the binary to upload, this software show how many cycles it takes to execute the code, and other informations.... But, i dont remenber where i saw this... =/

???

Read this before posting a programming question

How to use this forum

Can somebody help me?

wizarcl:
Sorry for my english and for my phone... which is faster: read a variable, verify and write only one time on the loop, or write every time? ex:

You can look at an assembled version of the code and the datasheet to determine the number of clock cycles, but in general, just writing the value to the variable will be faster.

Writing it every time is faster.

void loop(){
  if (variable != 0) {
    variable = 0;
  }
}

compiles to:

000000a8 <loop>:
  a8:   80 91 00 01     lds r24, 0x0100
  ac:   90 91 01 01     lds r25, 0x0101
  b0:   89 2b           or  r24, r25
  b2:   21 f0           breq    .+8         ; 0xbc <loop+0x14>
  b4:   10 92 01 01     sts 0x0101, r1
  b8:   10 92 00 01     sts 0x0100, r1
  bc:   08 95           ret

But,

void loop(){
  variable = 0;
}

compiles to:

000000a8 <loop>:
  a8:   10 92 01 01     sts 0x0101, r1
  ac:   10 92 00 01     sts 0x0100, r1
  b0:   08 95           ret

Thanks friends... How i can get the code in assembly? Like you posted

majenko

...

But... in the first loop{} microcontroller verify the variable and write only one time.... if i do not change this variable, microcontroller will check but will not do anything and the second loop{}, microcontroller will write every time..
If i have, three or four variables... In the second loop{} microcontroller will work more fast?

Doing the check takes as long as writing the variable.
However, why the obsession with this trivial matter most of the tine you have CPU cycles to burn. If not then you need a faster board.

wizarcl:
Thanks friends... How i can get the code in assembly? Like you posted

majenko

...

Turn on "verbose compiling". Do a Verify. You should see something like this in the last three lines of output:

/var/folders/1l/43x8v10s1v36trvjz3v92m900000gn/T/build6608686236955571651.tmp/sketch_aug22a.cpp.elf
/var/folders/1l/43x8v10s1v36trvjz3v92m900000gn/T/build6608686236955571651.tmp/sketch_aug22a.cpp.hex 
Binary sketch size: 1,154 bytes (of a 32,256 byte maximum)

Copy the name of the "elf" file (first line above) and use it in the line below in place of xxxxxx.elf :

avr-objdump -S xxxxxx.elf > somefile.txt

(Using a "command" or "console" window)

Thank you guys…