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
沒有留言:
發佈留言