zoukankan      html  css  js  c++  java
  • 测试代码执行时间的帮助类

    一同事写的测试代码执行时间的帮助类,

    // TimeHlper.h

    #pragma once

    #ifndef NL
    #define NL _T(" ")
    #endif

    #define DEBUG_YGS

    #define IDPTRACE_VAL(fmt, val) TRACE(NL _T(__FUNCTION__) _T(#val) fmt, val) // 输出变量
    #define IDPTRACE_INT(val) IDPTRACE_VAL(_T("%d"), val) // 输出INT

    //////////////////////////////////////////////////////////////////////
    // 代码效率统计 -BEGIN
    #define IDPCODEEFFICIE_BEGIN
    CIDPCodeEfficie code##__FUNCTION__(_T(__FUNCTION__))

    #define IDPCODEEFFICIE_TRACELINE
    code##__FUNCTION__.TraceFunc(__LINE__, _T(__FUNCTION__))

    class CIDPCodeEfficie
    {
    public:
    CIDPCodeEfficie(LPCTSTR lpszFlag = _T(""))
    {
    m_dBeginTime = GetCurTime();
    m_dAnchorTime = m_dBeginTime;
    m_strFlag = lpszFlag;
    }

    ~CIDPCodeEfficie()
    {
    //TRACE(_T(" [%s%08X][%d]: AllUsed "), m_strFlag, GetTickCount(), GetUsedTime(GetCurTime(), m_dBeginTime));
    TRACE(_T(" [%08X][%s------>AllUsed ======Time:%d] "), GetTickCount(), m_strFlag, GetUsedTime(GetCurTime(), m_dBeginTime));
    }

    VOID TraceFunc(int nLine = 0, LPCTSTR lpszFlag = _T(""))
    {
    CString strText;
    //strText.Format(_T("Func:%s_Line:%d"), lpszFlag, nLine);
    //TraceStep(strText);
    double dCurTime = GetCurTime();
    TRACE(_T(" [%08X][%s------>Line:%d======Time:%d]"), GetTickCount(), m_strFlag, nLine, GetUsedTime(GetCurTime(), GetAnchorTime()));
    SetAnchorTime(dCurTime);
    }

    VOID TraceStep(LPCTSTR lpszFlag = _T("")) // 输出上次输出时经过的时间
    {
    double dCurTime = GetCurTime();
    TRACE(_T(" [%s%08X][%d]: %s"), m_strFlag, GetTickCount(), GetUsedTime(GetCurTime(), GetAnchorTime()), lpszFlag);
    SetAnchorTime(dCurTime);
    }

    double GetBeginTime() const { return m_dBeginTime; }
    double GetAnchorTime() const { return m_dAnchorTime; }
    VOID SetAnchorTime(double dTime) { m_dAnchorTime = dTime; }

    DWORD GetUsedTime(double dEnd, double dBegin)
    {
    LARGE_INTEGER litmp;
    double dfMinus, dfFreq, dfTim;
    QueryPerformanceFrequency(&litmp);
    dfFreq = (double)litmp.QuadPart; // 时种频率
    dfMinus = (double)(dEnd-dBegin);
    dfTim = dfMinus / dfFreq;// 获得对应的时间值,单位为秒
    return DWORD(dfTim * 1000);
    }

    double GetCurTime()
    {
    LARGE_INTEGER litmp = {0};
    QueryPerformanceCounter(&litmp);
    return (double)litmp.QuadPart;
    }

    private:
    double m_dBeginTime;
    double m_dAnchorTime;
    CString m_strFlag;
    };

    //////////////////////////////////////////////////////////////////////
    // 代码效率统计 -End

    // ARTIST DEF

    |=======================================| | 既然选择了远方,便只顾风雨兼程! | |=======================================|
  • 相关阅读:
    SPSS-Friedman 秩和检验-非参数检验-K个相关样本检验 案例解析
    SPSS-多重响应-频率和交叉表案例分析(问卷调查分析)
    SPSS--回归-多元线性回归模型案例解析
    深入理解RunLoop
    杂七杂八集合
    单元测试
    笔记
    http断点续传
    iOS性能优化
    群聊协议
  • 原文地址:https://www.cnblogs.com/mr-m/p/3542591.html
Copyright © 2011-2022 走看看