プログラム実行時間/Cの経過時間を計算する

プログラム実行時間/ Cで経過した時間を計算する

ここでは、Cでプログラムの実行時間または経過時間を計算する簡単な方法を共有しました

/*calculate program execute time */
#include
#include

int main(int argc, char *argv[]) {
   time_t start, stop;
   clock_t ticks; long count;

   time(&start);
   // Do stuff
   int i=0;

   while(i<50000)
   {
    printf("Work work %d\n", i);
        i++;
        ticks = clock();

   }

   time(&stop);

   printf("Used %0.2f seconds of CPU time. \n", (double)ticks/CLOCKS_PER_SEC);
   printf("Finished in about %.0f seconds. \n", difftime(stop, start));
   return 0;
}