C++ 统计程序运行耗时的几种方法的总结
2015-05-22 16:26
681 查看
方法一 利用GetTickCount函数(ms)
代码:
CString
str;
longt1=GetTickCount();//程序段开始前取得系统运行时间(ms)
。。。。。。//to do sth
longt2=GetTickCount();//程序段结束后取得系统运行时间(ms)
str.Format("time:%dms",t2-t1);//前后之差即程序运行时间
AfxMessageBox(str);
方法二利用C/C++计时函数(s)
代码:
#include"time.h"
clock_t start, finish;
start =clock();
finish
=
clock();
printf("%f seconds\n",(double)(finish-start)/CLOCKS_PER_SEC);
方法三 利用CTime类 获取系统时间
代码:
CString str;
//获取系统时间
CTime tm;
tm=CTime::GetCurrentTime();
str=tm.Format("现在时间是%Y年%m月%d日 %X");
AfxMessageBox(str);
方法四 利用GetLocalTime类获取系统时间
SYSTEMTIME st;
CString strDate,strTime;
GetLocalTime(&st);
strDate.Format("M----",st.wYear,st.wMonth,st.wDay);
strTime.Format("-:-:-",st.wHour,st.wMinute,st.wSecond);
AfxMessageBox(strDate);
AfxMessageBox(strTime);
方法五 利用API函数
我目前找到的也就这几种方法,如果还有什么新的方法,和大家一起分享一下。
代码:
CString
str;
longt1=GetTickCount();//程序段开始前取得系统运行时间(ms)
。。。。。。//to do sth
longt2=GetTickCount();//程序段结束后取得系统运行时间(ms)
str.Format("time:%dms",t2-t1);//前后之差即程序运行时间
AfxMessageBox(str);
方法二利用C/C++计时函数(s)
代码:
#include"time.h"
clock_t start, finish;
start =clock();
finish
=
clock();
printf("%f seconds\n",(double)(finish-start)/CLOCKS_PER_SEC);
方法三 利用CTime类 获取系统时间
代码:
CString str;
//获取系统时间
CTime tm;
tm=CTime::GetCurrentTime();
str=tm.Format("现在时间是%Y年%m月%d日 %X");
AfxMessageBox(str);
方法四 利用GetLocalTime类获取系统时间
SYSTEMTIME st;
CString strDate,strTime;
GetLocalTime(&st);
strDate.Format("M----",st.wYear,st.wMonth,st.wDay);
strTime.Format("-:-:-",st.wHour,st.wMinute,st.wSecond);
AfxMessageBox(strDate);
AfxMessageBox(strTime);
方法五 利用API函数
BOOL QueryPerformanceCounter( LARGE_INTEGER *lpPerformanceCount // counter value );
我目前找到的也就这几种方法,如果还有什么新的方法,和大家一起分享一下。
相关文章推荐
- c/c++计算程序运行时间的几种方法
- C++中几种测试程序运行时间的方法
- C++中两种常用的记录程序运行时间的方法的总结
- c++统计程序运行时间的方法
- C++中两种常用的记录程序运行时间的方法的总结
- 【C++】C++中几种测试程序运行时间的方法
- 题目:C++中两种常用的记录程序运行时间的方法的总结
- C++ 记录程序运行时间的方法总结
- C++中几种测试程序运行时间的方法
- Java中计算程序运行耗时的方法对比
- C++ 项目中使用并发运行库的几种常用方法
- VS2010 c++编写的程序在别人的机子运行不了,缺少mfc100.dll, xxx100d.dll等的解决方法
- linux下c++多线程下用CLOCK()函数统计程序运行时间 2012-12-11 12:46:01 分类: C/C++ clock()函数的功能: 这个函数返回从“开启这个程序进程”到
- 调试Python程序的几种方法总结
- (转载)总结C++中的几种结构体初始化的方法
- opencv程序在未安装opencv环境下运行方法总结
- python程序运行时间的几种分析方法
- C++操作SQLITE获得查询结果集的几种方法总结
- c/c++在windows下获取时间和计算时间差的几种方法总结 【转】
- C++避免程序运行完后窗口一闪而过的方法