函数运行时间计算

#include <iostream>
#include <time.h>
using namespace std;

int main() {
   clock_t start, finish;
   double totaltime;
   start = clock();
   time_t new_cur_time = time(NULL);
   struct tm p_time;
   localtime_r(&new_cur_time, &p_time);
   static const int SIZE = 20;
   char new_en_time[SIZE] = {0};
   strftime(new_en_time, SIZE, "%Y-%m-%d %H:%M:%S", &p_time);           // 格式化当前时间
   cout << "当前时间为:" << new_en_time << endl;
   finish = clock();
   totaltime = (double)(finish-start)/CLOCKS_PER_SEC;
   cout << "此程序的运行时间为:" << totaltime << "秒!" << endl;
}

 

posted @ 2018-11-24 16:11  执著的追求  阅读(105)  评论(0)    收藏  举报