Warning: file_get_contents() [function.file-get-contents]: SSL: 远程主机强迫关闭了一个现有的连接。 in D:\wwwroot\huidong\wwwroot\function.inc.php on line 884

Warning: file_get_contents(https://whois.pconline.com.cn/jsLabel.jsp?ip=127.0.0.1) [function.file-get-contents]: failed to open stream: HTTP request failed! in D:\wwwroot\huidong\wwwroot\function.inc.php on line 884
快速测试一段代码的运行时间 - huidong

huidong

首页 | 会员登录 | 关于争取 2022 寒假做出汇东网 Ver3.0.0 !
搜索文章


double dfq;
LARGE_INTEGER fq, t_begin, t_end;
#define TIMEC_INIT    {QueryPerformanceFrequency(&fq);dfq=1.0/fq.QuadPart;}
#define TIMEC_BEGIN    QueryPerformanceCounter(&t_begin);
#define TIMEC_END    {QueryPerformanceCounter(&t_end);printf("%lf\n",(t_end.QuadPart-t_begin.QuadPart)*dfq);}

加在代码里,先TIMEC_INIT(一次即可),开始的时候BEGIN, 结束的时候END会自动输出时间(单位是秒)。


还有个仅DEBUG模式下才输出时间的(VS2019实测):

// 代码耗时计算(仅debug状态下有效)
#ifdef _DEBUG

double dfq;
LARGE_INTEGER fq, t_begin, t_end;
#define TIMEC_INIT    {QueryPerformanceFrequency(&fq);dfq=1.0/fq.QuadPart;}
#define TIMEC_BEGIN    QueryPerformanceCounter(&t_begin);
#define TIMEC_END    {QueryPerformanceCounter(&t_end);printf("%lf\n",(t_end.QuadPart-t_begin.QuadPart)*dfq);}

#else

#define TIMEC_INIT
#define TIMEC_BEGIN
#define TIMEC_END

#endif // _DEBUG




返回首页


Copyright (C) 2018-2024 huidong