c - Get interval between 2 operations using ctime? -


i interested in showing execution time program in c, @ diverse points, using ctime. have tried that, must not right...

int main() {      time_t tm1, tm2;     tm1 = time(null);     sleep(2);     tm2 = ctime(tm1);      printf("%d\n", tm2-tm1);     return 0; } 

do have suggestion or proper example? in advance

ctime() returns string representation of time passed it.

if want simple elapsed time, just:

    time_t t1, t2;     t1 = time(0);     sleep(2);     t2 = time(0);      printf("elapsed: %d\n", t2 - t1); 

see man ctime , man 2 time.


Comments