#include<windows.h>#include<ctime>#include<iostream>usingnamespacestd;intmain(){time_tres_1=time(nullptr);Sleep(1000);// do some stuff...
time_tres_2=time(nullptr);cout<<res_1<<endl;cout<<asctime(localtime(&res_1))<<endl;cout<<res_2-res_1<<'s'<<endl;return0;}/* 输出结果
1585457981
Sun Mar 29 12:59:41 2020
1s
*/
#include<windows.h>#include<chrono>#include<iostream>usingnamespacestd;intmain(){chrono::steady_clock::time_pointstart=chrono::steady_clock::now();Sleep(1000);// do some stuff...
chrono::steady_clock::time_pointend=chrono::steady_clock::now();chrono::duration<double>ans=end-start;cout<<ans.count()<<'s'<<endl;return0;}/* 输出:
1.01495s
*/
#include<windows.h>#include<iostream>usingnamespacestd;intmain(){DWORDstart=GetTickCount();Sleep(1000);// do some stuff...
DWORDend=GetTickCount();cout<<end-start<<"ms"<<endl;return0;}/*输出:
1016ms
*/
#include<windows.h>#include<iomanip>#include<iostream>usingnamespacestd;intmain(){ULONGLONGstart=GetTickCount64();Sleep(1000);// do some stuff...
ULONGLONGend=GetTickCount64();cout<<end-start<<"ms"<<endl;return0;}/* 输出:
1015ms
*/