Easily measure elapsed time

前端 未结 26 2698
栀梦
栀梦 2020-11-22 04:13

I am trying to use time() to measure various points of my program.

What I don\'t understand is why the values in the before and after are the same? I understand thi

26条回答
  •  死守一世寂寞
    2020-11-22 04:50

    As I can see from your question, it looks like you want to know the elapsed time after execution of some piece of code. I guess you would be comfortable to see the results in second(s). If so, try using difftime() function as shown below. Hope this solves your problem.

    #include 
    #include 
    
    time_t start,end;
    time (&start);
    .
    .
    .
    
    .
    .
    .
    time (&end);
    double dif = difftime (end,start);
    printf ("Elasped time is %.2lf seconds.", dif );
    

提交回复
热议问题