如何获取程序运行时间?
2008-04-18 13:36
337 查看
1. CTime 方法(秒级)
CTime t1 = CTime::GetCurrentTime();
Sleep(xxxx);
CTime t2 = CTime::GetCurrentTime();
CTimeSpan tSp = t2 - t1;
DWORD nSec = tSp.GetTotalSeconds();
// 取得累加上时、分之后所有的秒
// CTime是MFC类库
2. time 方法(秒级)
time_t t1;
time_t t2;
time(&t1);
Sleep(xxxx);
time(&t2);
unsigned tDiff = (unsigned)difftime(t2, t1);
// time_t就是unsigned型
3. _ftime 方法(毫秒级)
struct timeb ...{
time_t time; // 逝去的秒
unsigned short millitm; // 不足秒的毫秒部分
short timezone; // 与时区相关?
short dstflag; // 与时区相关?
};
struct _timeb tb1;
struct _timeb tb2;
_ftime(tb1);
Sleep(xxxx);
_ftime(tb2);
unsigned nMs = tb2.millitm - tb1.millitm + (tb2.time - tb1.time)*1000;
4.取日期
_strdate(char buf[]); // 如:05/03/94
5.取时间
_strtime(char buf[]); // 如:21:51:03
6.附录
struct timeb ...{
time_t time; // 逝去的秒
unsigned short millitm; // 不足秒的毫秒部分
short timezone; // 与时区相关?
short dstflag; // 与时区相关?
};
time_t 就是unsigned型
struct tm ...{
tm_sec, // Seconds after minute (0 – 59)
tm_min, // Minutes after hour (0 – 59)
tm_hour, // Hours since midnight (0 – 23)
tm_mday, // Day of month (1 – 31)
tm_mon, // Month (0 – 11; January = 0)
tm_year, // Year (current year minus 1900)
tm_wday, // Day of week (0 – 6; Sunday = 0)
tm_yday, // Day of year (0 – 365; January 1 = 0)
tm_isdst, // Always 0 for gmtime
};
函数 char* ctime(const time_t* timer);
把time_t(逝去的秒数)根据时区,转化为相应的时间的字符串
如:"Apr 29 12:25:12 1994"
函数 struct tm* gmtime(const time_t* timer);
函数 struct tm* localtime(const time_t* timer);
把time_t(逝去的秒数)转化为“全球时”或“本地时”的tm结构
函数 time_t mktime(struct tm *timeptr);
把tm结构转化为time_t(逝去的秒数)
函数 char *asctime(const struct tm *timeptr);
把tm结构转化为字符串,如"Sun May 01 20:27:01 1994"
函数 size_t strftime(char *strDest, size_t maxsize, const char *format, const struct tm *timeptr);
把tm结构格式化,得到想要的某种格式
函数 _tzset
设置环境变量
变量 _tzname
操作全局变量
CTime t1 = CTime::GetCurrentTime();
Sleep(xxxx);
CTime t2 = CTime::GetCurrentTime();
CTimeSpan tSp = t2 - t1;
DWORD nSec = tSp.GetTotalSeconds();
// 取得累加上时、分之后所有的秒
// CTime是MFC类库
2. time 方法(秒级)
time_t t1;
time_t t2;
time(&t1);
Sleep(xxxx);
time(&t2);
unsigned tDiff = (unsigned)difftime(t2, t1);
// time_t就是unsigned型
3. _ftime 方法(毫秒级)
struct timeb ...{
time_t time; // 逝去的秒
unsigned short millitm; // 不足秒的毫秒部分
short timezone; // 与时区相关?
short dstflag; // 与时区相关?
};
struct _timeb tb1;
struct _timeb tb2;
_ftime(tb1);
Sleep(xxxx);
_ftime(tb2);
unsigned nMs = tb2.millitm - tb1.millitm + (tb2.time - tb1.time)*1000;
4.取日期
_strdate(char buf[]); // 如:05/03/94
5.取时间
_strtime(char buf[]); // 如:21:51:03
6.附录
struct timeb ...{
time_t time; // 逝去的秒
unsigned short millitm; // 不足秒的毫秒部分
short timezone; // 与时区相关?
short dstflag; // 与时区相关?
};
time_t 就是unsigned型
struct tm ...{
tm_sec, // Seconds after minute (0 – 59)
tm_min, // Minutes after hour (0 – 59)
tm_hour, // Hours since midnight (0 – 23)
tm_mday, // Day of month (1 – 31)
tm_mon, // Month (0 – 11; January = 0)
tm_year, // Year (current year minus 1900)
tm_wday, // Day of week (0 – 6; Sunday = 0)
tm_yday, // Day of year (0 – 365; January 1 = 0)
tm_isdst, // Always 0 for gmtime
};
函数 char* ctime(const time_t* timer);
把time_t(逝去的秒数)根据时区,转化为相应的时间的字符串
如:"Apr 29 12:25:12 1994"
函数 struct tm* gmtime(const time_t* timer);
函数 struct tm* localtime(const time_t* timer);
把time_t(逝去的秒数)转化为“全球时”或“本地时”的tm结构
函数 time_t mktime(struct tm *timeptr);
把tm结构转化为time_t(逝去的秒数)
函数 char *asctime(const struct tm *timeptr);
把tm结构转化为字符串,如"Sun May 01 20:27:01 1994"
函数 size_t strftime(char *strDest, size_t maxsize, const char *format, const struct tm *timeptr);
把tm结构格式化,得到想要的某种格式
函数 _tzset
设置环境变量
变量 _tzname
操作全局变量
相关文章推荐
- Go语言如何计算程序运行的时间效率,获取时间差
- Unix/Linux环境C编程入门教程(22) C/C++如何获取程序的运行时间
- Unix/Linux环境C编程入门教程(22) C/C++如何获取程序的运行时间
- 如何精确计算程序运行时间——精确获取时间(QueryPerformanceCounter)
- 获取程序的运行时间
- 紧急求助国内外大侠:如何编写程序得到正在运行的ppt的当前页码和运行时间?
- C# Winform程序如何获取运行路径, 控制台也可以
- C语言中如何计算程序运行的时间
- C++中如何计算程序运行的时间
- [转]VC获取系统时间、程序运行时间
- windows/vs如何获取程序内存使用量和时间花费
- 如何保证程序运行时系统时间不被修改!
- [CF Skills]如何在预定的时间运行你的程序
- 如何判断程序加载时间 方法 运行时间
- 如何计算程序运行的时间(clock的正确使用)
- 运行hadoop程序,如何在map中获取输入数据的全路径(fullpath)
- 获取系统时间、程序运行时间
- C/C++如何以秒计时程序运行时间
- 如何获取程序执行时间的高精度时间?