方法一:用clock_t
#include#include using namespace std;clock_t begin = clock();..............clock_t end = clock();double cost = (double)(end - begin)/ (double)CLOCKS_PER_SEC * 1000;cout << "运行时间:" << cost << "ms" << endl;
方法二: 用time_t
#includetime_t begin;time_t end;begin = time(NULL);................程序代码end = time(NULL);cout << "程序运行时间: " << end - begin << "second " << endl;