C + + Acquisition time
Header file Chrono, namespace Std.
Now time
Std::chrono::system_clock::now () returns the current time of the system clock
Clock
Std::chrono::system_clock represents the current time of the system, is an unstable clock, and provides a function to convert a point in time to a value of time_t type
Std::chrono::steady_clock represents a stable clock, so-called stability refers to the call now (), whose value is always greater than 1 times.
Delay
Std::this_thread::sleep_for () and Std::this_thread::sleep_until ()
Std::this_thread::sleep_for (std::chrono::milliseconds (100)); Wait 100ms
1 #define_crt_secure_no_warnings2 3#include <iostream>4#include <string>5#include <sstream>6#include <iomanip>7#include <chrono>8 9STD::stringgettimestr ()Ten { OneStd::chrono::system_clock::time_point now =Std::chrono::system_clock::now (); Atime_t TT =std::chrono::system_clock::to_time_t (now); - structTM LTM = {0}; -Localtime_s (<m, &TT); the Std::stringstream stm; -STM << Std::setfill ('0'); -STM << STD::SETW (4) << (Ltm.tm_year +1900) <<"-"; -STM << STD::SETW (2) << (Ltm.tm_mon +1) <<"-"; +STM << STD::SETW (2) << (Ltm.tm_mday) <<" "; -STM << STD::SETW (2) << (Ltm.tm_hour) <<"-"; +STM << STD::SETW (2) << (ltm.tm_min) <<"-"; ASTM << STD::SETW (2) <<(ltm.tm_sec); at - returnstm.str (); - } - - voidMyTestvoid) - { inStd::cout <<"<<<<<<<<<<<<<<<<<<<<<<<<<"<<Std::endl; - toStd::chrono::steady_clock::time_point Tbegin =Std::chrono::steady_clock::now (); +Std::cout << gettimestr (). C_STR () <<Std::endl; -Std::chrono::steady_clock::time_point tend =Std::chrono::steady_clock::now (); theStd::chrono::milliseconds used = Std::chrono::d uration_cast<std::chrono::milliseconds> (Tend-tbegin); *Std::cout << used.count () <<"Ms"<<Std::endl; $ Panax NotoginsengStd::cout <<"<<<<<<<<<<<<<<<<<<<<<<<<<"<<Std::endl; - } the + intMainintargcChar* argv[],Char*envp[]) A { the mytest (); + -System"Pause"); $ return 0; $}
Operation Result:
C + + Acquisition time