目录
一、统计时间
二、输出变量
一、统计时间
首先挂库"time.h"
#include "time.h"start = clock();// 测试运行时间的程序段end = clock();float TimeValue;TimeValue=end-start;
这里TimeValue就是程序段运行的时间,单位为毫秒(ms)。
二、输出变量
可以考虑把TimeValue输出到CSV文件中
输出挂库<iostream>、<fstream>、<stdlib.h>
#include "time.h"#include <iostream>#include <fstream>#include <stdlib.h>using namespace std;start = clock();// 测试运行时间的程序段end = clock();float TimeValue;TimeValue=end-start;char cFileName1[300] = { 0 };sprintf(cFileName1, "D:\\CodeTime.csv");// 向csv文档中写入数据ofstream dataFile1;dataFile1.open(cFileName1, ios::out | ios::trunc);dataFile1 << TimeValue << ",";// 写入数据dataFile1.close(); // 关闭文档
如下图所示,为某程序的运行时间:1332ms