how to measure the number of clock cycles from execution time of a code

I am using micros() function to get the execution time of my code on Mega 2560. But can anyone tell me how to get the number of clock cycles required for executing it.

Divide by 62.5ns

But can anyone tell me how to get the number of clock cycles required for executing it.

Executing what?

executing my code

what code?

Where?

Micros() is only good to 4 usecs. As in 4, 8, 12, 16, never 3 or 6 or 11.

4 micros is 64 cycles at 16 MHz and there is a rub, most UNO's use a resonator that is not super accurate and changes slightly with temperature so if by cycles you mean time then it's only so close.

..but it gets more accurate if you further divide by the number of times you did it

The tight timing routines I've seen use count-loops to get down to sub-usec timing and were old when I got here.

Come to think of it, you might have posted in one or two of those threads, AWOL.

Yeah, imagine that. Of course, you have to be really careful of the compiler being clever optimising-away results.

15-20 years ago the one I used just showed lines compiled.