This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How can I Count clock cycle consumption for a Piece of C Code

Hello
I am using C51 Compiler for AT89C51.
How can I Count clock cycle consumption for a Piece of C Code e.g
P1=(int)(((sin((2*PI)*(((double) (k++))/MAX))+1)/2)*BYTE);

?????????
How many clks it will take ???
????????

Parents
  • Looking at only the C source code, you can't.

    Using an emulator or uVision's simulator, set a breakpoint at this C statement and the statement that follows it. Execute up to the first breakpoint and (using uVision's simulator, at least) note the clocks value, then execute up to the next breakpoint and subtract the noted clocks value from the new clocks value and there you have it.

Reply
  • Looking at only the C source code, you can't.

    Using an emulator or uVision's simulator, set a breakpoint at this C statement and the statement that follows it. Execute up to the first breakpoint and (using uVision's simulator, at least) note the clocks value, then execute up to the next breakpoint and subtract the noted clocks value from the new clocks value and there you have it.

Children