Home » Community » Newbie corner » time measurement :: RTIMING, TimeStop, GetTickCount
Re: time measurement :: RTIMING, TimeStop, GetTickCount [message #36202 is a reply to message #36180] |
Fri, 11 May 2012 20:23   |
|
I just accidentally stumbled upon the new C++11 way to measure times. With <chrono> header, you can do something like this:
#include <chrono> //requires -std=c++11
#include <Core/Core.h>
using namespace Upp;
CONSOLE_APP_MAIN{
auto start = std::chrono::high_resolution_clock::now();
Sleep(1); //execute your code here
auto duration = std::chrono::high_resolution_clock::now() - start;
auto result=std::chrono::duration_cast<std::chrono::microseconds>(duration).count();
LOG(result << " us");
}
Sorry for the stupid use of the "auto" keyword... I was too lazy to type the full type names for time_point and duration - they are almost as long as in Java Reference for the header can be found at this great site: http://en.cppreference.com/w/cpp/chrono (thanks Sender Ghost for showing me )
The resolution seems to be in microseconds (when I formatted the output to nanoseconds, it showed only multiples of 1000) on my system, but it might vary on other machines/platforms.
Best regards,
Honza
|
|
|
 |
|
time measurement :: RTIMING, TimeStop, GetTickCount
|
 |
|
Re: time measurement :: RTIMING, TimeStop, GetTickCount
|
 |
|
Re: time measurement :: RTIMING, TimeStop, GetTickCount
|
 |
|
Re: time measurement :: RTIMING, TimeStop, GetTickCount
|
 |
|
Re: time measurement :: RTIMING, TimeStop, GetTickCount
|
 |
|
Re: time measurement :: RTIMING, TimeStop, GetTickCount
|
 |
|
Re: time measurement :: RTIMING, TimeStop, GetTickCount
By: Didier on Wed, 09 May 2012 22:23
|
 |
|
Re: time measurement :: RTIMING, TimeStop, GetTickCount
|
 |
|
Re: time measurement :: RTIMING, TimeStop, GetTickCount
|
 |
|
Re: time measurement :: RTIMING, TimeStop, GetTickCount
|
Goto Forum:
Current Time: Tue Jul 08 18:21:43 CEST 2025
Total time taken to generate the page: 0.02669 seconds
|