Linux下测试程序的运行时间
简单写个小的知识点,测试代码的性能,测试代码执行的时间。
要包含头文件
#include "time.h"
#include <sstream>
代码如下:
/*...............测试程序运行时间...................*/ time_t startT,endT; double totalT; startT = time(NULL); // 假设一条语句执行10000次 // obj.MysqlInsert("insert into children values(22,'zhangsan',50)"); //插入一行数据 for(int i=0; i<10000; ++i) { stringstream ss; ss << "insert into children values("<< i << ",'cershi',10)"; obj.mysql_Insert(ss.str()); //插入一行数据 } //这里插入了1万行数据 endT = time(NULL); totalT = difftime(endT,startT); cout << "程序执行的时间为:" << totalT << endl;
当然还有其他的方法,这只是我用的很简单的一种。记录下来