⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mtime.cpp

📁 跨平台C++基础库
💻 CPP
字号:

#include "MCRT/mtime.h"

#ifndef WIN32 //! WIN32
#   include <sys/types.h>
#   include <sys/time.h>
#endif //end WIN32

MTime::MTime()
{
}

MTime::~MTime()
{
}

void MTime::Start()
{
    MTime::gettimeofday( this->m_startTime );
}

void MTime::Stop()
{
    MTime::gettimeofday( this->m_endTime );
}

mULong MTime::Count()
{
    mULong  timeElapsed =   0;

    //a max reasonable time unit is hour
    if ( this->m_endTime.tv_usec < this->m_startTime.tv_usec )
    {
        this->m_endTime.tv_usec +=  1000000;
        ++ this->m_startTime.tv_sec;
    }
    if ( this->m_endTime.tv_sec < this->m_startTime.tv_sec )
    {
        this->m_endTime.tv_sec  +=  86400;  //24*3600;
    }

    timeElapsed =   (this->m_endTime.tv_sec - this->m_startTime.tv_sec) * 1000 + (this->m_endTime.tv_usec - this->m_startTime.tv_usec) / 1000;

    return timeElapsed;
}

void MTime::gettimeofday( MTime_val& mtime )
{
#ifdef WIN32
    SYSTEMTIME  curSysTime;
    ::GetSystemTime( &curSysTime );

    mtime.tv_sec    =   curSysTime.wHour * 3600 + curSysTime.wMinute * 60 + curSysTime.wSecond;
    mtime.tv_usec   =   curSysTime.wMilliseconds * 1000;
#else //! WIN32
    struct timeval  timePoint;
    ::gettimeofday( &timePoint, NULL );

    mtime.tv_sec    =   timePoint.tv_sec;
    mtime.tv_usec   =   timePoint.tv_usec;
#endif //end WIN32
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -