作者:彭元蓮_198 | 来源:互联网 | 2023-10-11 19:25
方法一:要包含头文件#includetime.h#include代码如下:[cpp]viewplaincopy*.
方法一:
要包含头文件
#include "time.h" #include 代码如下: -
- time_t startT,endT;
- double totalT;
- startT = time(NULL);
-
-
-
- for(int i&#61;0; i<10000; &#43;&#43;i)
- {
- stringstream ss;
- ss << "insert into children values("<< i << ",&#39;cershi&#39;,10)";
- obj.mysql_Insert(ss.str());
- }
-
- endT &#61; time(NULL);
- totalT &#61; difftime(endT,startT);
- cout << "程序执行的时间为&#xff1a;" << totalT << endl;
方法二&#xff1a;
#include
#include
#include
int main()
{
struct timeval tpstart,tpend;
float timeuse;
gettimeofday(&tpstart,NULL);
for(int i&#61;0;i<10;i&#43;&#43;)
{
usleep(200000);//暂停200ms
}
gettimeofday(&tpend,NULL);
timeuse&#61;1000000*(tpend.tv_sec-tpstart.tv_sec)&#43;tpend.tv_usec-tpstart.tv_usec;
timeuse/&#61;1000000;
printf("Used Time:%f\n",timeuse);
return 0;
}
方法三&#xff1a;
在执行程序前&#xff0c;加time&#xff0c;如&#xff1a;输入time./abc