timer
-
Hi ! I need to check in a C++ app, as precisely as possible, the time spent by the processor in a function. I have no idea where to start ! Any help will be greatly appreciated ! Jerome
-
Hi ! I need to check in a C++ app, as precisely as possible, the time spent by the processor in a function. I have no idea where to start ! Any help will be greatly appreciated ! Jerome
If you have access to the source code of the program, and the version of your Visual Studio installation is Professional or Enterprise, then you can do a profiling of your code, which gives you more or less accurate summaries of the time spent by the program in each function. You can start learning about profiling in Visual Studio with Cornell University tutorial Profiling with MS Visual Studio Tools. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
-
Hi ! I need to check in a C++ app, as precisely as possible, the time spent by the processor in a function. I have no idea where to start ! Any help will be greatly appreciated ! Jerome
Hi Jerome. Here's a simple class, it's not my idea, unfortunately I don't know whose copyright it is, I think it's from somwhere at CP: #pragma once class CDuration { protected: LARGE_INTEGER m_liStart; LARGE_INTEGER m_liStop; LONGLONG m_llFrequency; LONGLONG m_llCorrection; public: CDuration(void); void Start(void); void Stop(void); long GetDuration(void) const; }; inline CDuration::CDuration(void) { LARGE_INTEGER liFrequency; QueryPerformanceFrequency(&liFrequency); m_llFrequency = liFrequency.QuadPart; // Calibration Start(); Stop(); m_llCorrection = m_liStop.QuadPart-m_liStart.QuadPart; } inline void CDuration::Start(void) { // Ensure we will not be interrupted by any other thread for a while Sleep(0); QueryPerformanceCounter(&m_liStart);} inline void CDuration::Stop(void) {QueryPerformanceCounter(&m_liStop);} inline long CDuration::GetDuration(void) const { return (long)(m_liStop.QuadPart-m_liStart.QuadPart-m_llCorrection)*1000000.0 / m_llFrequency;} usage e.g.: CDuration durat; durat.Start(); FunctionCallToMeasure(); durat.Stop(); long ms_needed = durat.GetDuration(); I think the GetDuration return gives the time in milliseconds. I try to find the docu, then I can tell you more! Good Luck, Flo
-
Hi Jerome. Here's a simple class, it's not my idea, unfortunately I don't know whose copyright it is, I think it's from somwhere at CP: #pragma once class CDuration { protected: LARGE_INTEGER m_liStart; LARGE_INTEGER m_liStop; LONGLONG m_llFrequency; LONGLONG m_llCorrection; public: CDuration(void); void Start(void); void Stop(void); long GetDuration(void) const; }; inline CDuration::CDuration(void) { LARGE_INTEGER liFrequency; QueryPerformanceFrequency(&liFrequency); m_llFrequency = liFrequency.QuadPart; // Calibration Start(); Stop(); m_llCorrection = m_liStop.QuadPart-m_liStart.QuadPart; } inline void CDuration::Start(void) { // Ensure we will not be interrupted by any other thread for a while Sleep(0); QueryPerformanceCounter(&m_liStart);} inline void CDuration::Stop(void) {QueryPerformanceCounter(&m_liStop);} inline long CDuration::GetDuration(void) const { return (long)(m_liStop.QuadPart-m_liStart.QuadPart-m_llCorrection)*1000000.0 / m_llFrequency;} usage e.g.: CDuration durat; durat.Start(); FunctionCallToMeasure(); durat.Stop(); long ms_needed = durat.GetDuration(); I think the GetDuration return gives the time in milliseconds. I try to find the docu, then I can tell you more! Good Luck, Flo
Thank you a lot for your help ! Jerome
-
Thank you a lot for your help ! Jerome
Hi Jerome there you find the article, source and demo: http://www.codeproject.com/cpp/duration.asp what is your app made for? mfg HintiFlo
-
Hi Jerome there you find the article, source and demo: http://www.codeproject.com/cpp/duration.asp what is your app made for? mfg HintiFlo
Thank you for the information ! I'm working on a real-time App, which controls a machine, but we're having problems reaching the required speed of the machine. Thus, I wanted to check where, in the software, we are loosing time ! It's not easy !!! Tanks again and best regards, (or mfg, should I say !!!;-) ) Jerome