📄 datatest.c
字号:
/*时间/日期管理实例*/
/*DataTest.c*/
#include < time.h>
#include <stdio.h>
#include <math.h>
/*耗时运算函数*/
void function()
{
unsigned int i,j;
double y;
for(i=0;i<5000;i++)
for(j=0;j<4000;j++)
y=sin((double)i);
}
main()
{
time_t t;
struct tm nowtime ,*pt;
char *sTime;
struct timeval tpstart,tpend;
float timeuse;
/*获取系统时间*/
t=time(NULL);
pt=&nowtime;
/*把time_t结构的时间表示为tm结构*/
pt=localtime(&t);
/*转换为字符串*/
sTime=asctime(pt);
printf("Now time is %s\n",sTime);
/*计算执行上面的函数所需要的时间*/
gettimeofday(&tpstart,NULL);
function();
gettimeofday(&tpend,NULL);
timeuse=1000000*(tpend.tv_sec-tpstart.tv_sec)+
tpend.tv_usec-tpstart.tv_usec;
timeuse/=100000;
printf("Used Time:%f\n",timeuse);
exit(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -