Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to previous messageGo to previous message
dolik.rce is currently offline  dolik.rce
Messages: 1791
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

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 Smile Reference for the header can be found at this great site: http://en.cppreference.com/w/cpp/chrono (thanks Sender Ghost for showing me Wink )

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
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Search for constant and show it....
Next Topic: How do I 'check' a Switch control
Goto Forum:
  


Current Time: Tue Jul 08 18:21:43 CEST 2025

Total time taken to generate the page: 0.02669 seconds