Go Down

### Topic: how many clock cycles take this code to be executed? (Read 1 time)previous topic - next topic

#### eng_mac

##### Jul 02, 2013, 04:08 pm
hallo everybody,
i am impeleneting a protocol on arduino due and timing is very important , i want to know
how many clock cycles or the time in microsecond take this code to be executed?
if (counts >=0 && counts <=80) b1 = 1;
else if(counts >=330 && counts <=410) b1 = 2;
else if(counts >=450 && counts <=530) b1 = 3;
else if(counts >=820 && counts <=1024) b1 = 4;
and how many clock cycles take the for loop to check condition and make anew loop?

Thanks

#### Gericom

#1
##### Jul 02, 2013, 04:22 pm
If you exactly want to know how long a piece of code takes, you're better off with asm. Because you never know what a compiler will produce.

#### schwingkopf

#2
##### Jul 02, 2013, 07:02 pm
`int t1, t2;t1 = micros();if (counts >=0 && counts <=80) b1 = 1;  else if(counts >=330 && counts <=410) b1 = 2;  else if(counts >=450 && counts <=530) b1 = 3;  else if(counts >=820 && counts <=1024) b1 = 4;t2 = micros();Serial.println(t2-t1, DEC);`