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 » U++ Library support » U++ Core » High resolution TimeStop code
Re: High resolution TimeStop code [message #44407 is a reply to message #44394] Fri, 06 March 2015 18:19 Go to previous messageGo to previous message
Didier is currently offline  Didier
Messages: 736
Registered: November 2008
Location: France
Contributor
Hi Cbporter and Mirek,

Here is what I use when need very precise timings, it works for Win and Linux (notice the 'timeType': that is intended to be used by client classes in order make the code portable accross OS.

HWTiming is the 'Timer Facility' type that must be used in code.

HwTiming.h
#ifdef WIN32
	#include <Windows.h>
	class windowsHWTiming
	{
		protected:
			windowsHWTiming(void);
		
		public:
			typedef struct 
			{
			  signed __int64 nTicksCnt;
			} timeType;
		
			inline double diff_ms(timeType& p_start, timeType& p_end)
			{
				return (double(p_end.nTicksCnt-p_start.nTicksCnt)/double(m_TickPerSecond)*1000.);
			};
			
			inline timeType getTime(void)
			{
				timeType res;
				QueryPerformanceCounter((LARGE_INTEGER*)&res.nTicksCnt);
				return res;
			};
	
		private:
			signed __int64 m_TickPerSecond;
	};

	typedef windowsHWTiming HWTiming;

#else
	#include <time.h>
	class LinuxHWTiming {
		protected:
			LinuxHWTiming() {};
			
		public:
			typedef timespec timeType;
			
			// prend le temps exact
			static inline timeType getTime()
			{
				timeType t;
				clock_gettime(CLOCK_REALTIME, &t);
				return t;
			}
			
			// renvoie la difference en ms (milli-secondes)
			static inline double diff_ms(timeType& t1, timeType& t2)
			{
				return ((t2.tv_sec-t1.tv_sec)*1000.0 + (t2.tv_nsec-t1.tv_nsec)/1000000.0); 
			}
	};

	typedef LinuxHWTiming HWTiming;
#endif


HwTiming.cpp
#include "HWTiming.h"

#ifdef WIN32

		windowsHWTiming::windowsHWTiming(void)
		{
			 QueryPerformanceFrequency((LARGE_INTEGER*)&m_TickPerSeco nd);
		};
#endif

[Updated on: Fri, 06 March 2015 18:20]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: CoWork::Finish() can wait in a worker thread while there are jobs to do
Next Topic: Vector< Vector<int>> issue
Goto Forum:
  


Current Time: Mon Aug 25 03:56:34 CEST 2025

Total time taken to generate the page: 0.06046 seconds