Pages - Menu

標籤

AWS (1) bash (1) Boost (2) C (2) CMake (2) Concurrency_Programming (3) CPP (37) Database (2) DNS (1) Docker (4) Docker-Compose (1) ELK (1) emacs (4) gcp (1) gdrive (1) git (1) gitbash (2) gitlab (1) kvm (4) Linux (5) MT4 (4) MT5 (4) Multicast (2) MySQL (2) Nijatrader8 (1) OpenCV (1) Python (4) QT5 (1) R (1) rdp (3) screenshot (1) ssh (3) Tabnine (1) TCP (1) TensorFlow (1) Tools (12) Ubuntu_1904 (11) Ubuntu_20_04 (5) UDP (1) VS2010 (1) VS2015 (1) VS2019 (1) WebServer (1) Win10 (1) winmerge (1) WSL (1) xrdp (1)

搜尋此網誌

2020年4月29日星期三

Count Timer

Aim

This is an example showing how to use CountTimer.

Build and Run


mkdir build
cd build
cmake -G Ninja ../CountTimer -DCMAKE_BUILD_TYPE=Debug
ninja
./src/CountTimer

Source

#include <iostream>
#include <thread>

#include "CountTimer.h"

// usage: ./CountTimer
void SimpleStartStop()
{
    std::cout << "Simple Start Stop:" << std::endl;
    using namespace std::chrono_literals;
    CountTimer timer;
    timer.Start();
    std::this_thread::sleep_for(200ms);
    timer.Stop();
    std::cout << "Second: " << timer.GetSecond()
              << " MSecond: " << timer.GetMSecond()
              << " NSecond: " << timer.GetNSecond() << std::endl;
}
void MovingStartStop()
{
    std::cout << "Moving Start Stop:" << std::endl;
    using namespace std::chrono_literals;
    CountTimer timer;
    timer.Start();
    for (int i = 0; i < 3; i++)
    {
        std::this_thread::sleep_for(500ms);
        timer.MovingStop();
        std::cout << "Second: " << timer.GetSecond()
                  << " MSecond: " << timer.GetMSecond()
                  << " NSecond: " << timer.GetNSecond() << std::endl;
    }
}
void TimeToString()
{
    std::cout << "Time To String:" << std::endl;
    using namespace std::chrono_literals;
    CountTimer timer;
    timer.Start();
    std::cout << "StartTimeGmt: " << timer.ToStringStartTime() << " StartTimeLocal: " << timer.ToStringStartTime(false) << std::endl;
    std::this_thread::sleep_for(1s);
    timer.Stop();
    std::cout << "StopTimeGmt: " << timer.ToStringStopTime() << " StopTimeLocal: " << timer.ToStringStopTime(false) << std::endl;
}
int main(int argc, char *argv[])
{
    SimpleStartStop();
    MovingStartStop();
    TimeToString();

    return 0;
}

Output

Simple Start Stop:
Second: 0 MSecond: 200 NSecond: 200091
Moving Start Stop:
Second: 1 MSecond: 500 NSecond: 500089
Second: 1 MSecond: 1000 NSecond: 1000210
Second: 2 MSecond: 1500 NSecond: 1500337
Time To String:
StartTimeGmt: 2020-04-30 02:28:25 StartTimeLocal: 2020-04-30 10:28:25
StopTimeGmt: 2020-04-30 02:28:26 StopTimeLocal: 2020-04-30 10:28:26

沒有留言:

發佈留言