How to get cpu cycles between to operations in c program with BBB

Hi all,

I want to measure the number of cpu cycles between two operations in a c program. I am running a BBB rev C.1 on Debian (3.8.13-bone70). My code is pretty simple:

#include <stdio.h>
#include <time.h>

int main(void) {
clock_t start,stop;

int j;

; // burn time


printf(“used cycles: %f\n”,(long)(stop-start));

return (0);


The output is not satisfiing
root@beaglebone:/home/debian# ./getCycles
used cycles: 0.000000

This is the way I always did that in the past as far as I remember. Did I miss something? Maybe like additional support packages? Thank you in advance!

The compiler destroyed your for loop probably, because nothing useful is inside.
Try to turn the optimizations off.


In my productive system I indeed have true operations in the for loop, I just left them out. Also if I print out the value of clock() I also receive a 0.00000. For me it looks like the clock might not be initialized? But don’t know how to enable or initialize it…

Google works wonders for questions like these :wink: