|
Sounds a bit like profiling and the profiler uses QueryPerformanceCounter[^].
You have to use QueryPerformanceFrequency to know the resolution of the performance counter.
N.B. Use these functions for measuring time for debug purposes and optimization only!
If this is about a periodic operation to be done in the code, you should use the multimedia timers as WalderMort suggested.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
|
|
|
|
|
Thanks Roger!
QueryPerformanceCounter has a setback which not only measures the time elapsed (consumed) by current process -- but also the time consumed by the total running process at the same time in a system. Right?
What is a multimedia timer? Could you provide a link of MSDN please?
regards,
George
|
|
|
|
|
George_George wrote: QueryPerformanceCounter has a setback which not only measures the time elapsed (consumed) by current process -- but also the time consumed by the total running process at the same time in a system. Right?
Right! It's like getting a timestamp from the CPU.
Well, George, what do you really want to use it for?
Of course I can provide links to functions regarding the multimedia timers, but I'd like to make sure I suggest the best solution for your problem and in order to do that I need to know what you're trying to do.
Read about multimedia timers here[^].
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
|
|
|
|
|
Thanks Roger!
I have a simple application to do I/O test, and I want to draw some picture about the time consumed by each step of the application. Do you think QueryPerformanceCounter is enough?
regards,
George
|
|
|
|
|
George_George wrote: Do you think QueryPerformanceCounter is enough?
Yep, I would use the performance counter in this situation.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
|
|
|
|
|
Thanks Roger!
I have taken a look of multimedia timer. I think it could only provide callback approach in a regular interval. Is it correct? If it is, I think it does not apply to my requirement, do you agree?
regards,
George
|
|
|
|
|
George_George wrote: I think it could only provide callback approach in a regular interval. Is it correct?
Partly.
I think the most common way to use a multimedia timer is to let the timer set an event when it expires which unleashes a thread that is waiting on the event.
However, it still acts as a periodic timer.
George_George wrote: I think it does not apply to my requirement, do you agree?
I fully agree. Like i said, I would go for the performance counter in this situation.
Don't forget to add error checking in case the performance counter is unsupported and you also have to call QueryPerformanceFrequency in order to know the resolution of the performance counter. You'll find information about this if you follow the link I provided in my first post.
--
Roger
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
|
|
|
|
|
Man, how could a periodic timer be used to calculate the elapsed time? For example, I set the inverval of the timer to 10 seconds -- but how could I know the elapsed time of the function I am going to test will elapse exactly 10 seconds?
Roger Stoltz wrote: However, it still acts as a periodic timer.
regards,
George
|
|
|
|
|
George_George wrote: Man, how could a periodic timer be used to calculate the elapsed time?
You can, but it would be the wrong tool for the job.
Why are you asking? If you're referring to my first post I just wanted to cover the possibility that I'd misunderstood your question and make sure you don't think you can use the performance counter as a waitable timer.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
|
|
|
|
|
Hi Roger!
I think your method should work (because I think you are experienced about the various timers), but I am not fully understand your points. So, could you post in details which function in MultiMedia timer are you going to use, and how you use it in a couple of lines of virtual code please?
regards,
George
|
|
|
|
|
I'm not sure why you are still discussing timers. Roger recommendeded repeatedly that you use
the performance counter.
Periodic timers aren't much help to calculate elapsed time. You need a reference time that you
can check at the start, check at the finish, and calculate the delta. That's what the performance
counter is for.
Even a multimedia timer at true 1ms resolution isn't accurate enough IMO (unless the function(s)
you are timing always take many seconds. 1ms is a long time.
Mark
|
|
|
|
|
Hi Mark,
What makes me confused is, I think multimedia timer is a periodic timer. So, how could multimedia timer be used for calculating elapsed time?
regards,
George
|
|
|
|
|
the performance counter is NOT a periodic timer. It's like get tick count with much better
resolution. On my 3.2GHz box it's incremented on every clock tick (3.2GHz frequency).
You could use GetTickCount if 10ms-55ms accuracy is good enough.
Get the count, run the function, get the count again. Subtract and you have your elapsed time.
Factor in the frequency to convert to seconds, milliseconds, nanoseconds, whatever.
Mark
|
|
|
|
|
Thanks Mark!
If user changed the system time during my application runs, will the tick counter be impacted?
(I am wondering whether the counter values are dependent on system time.)
regards,
George
|
|
|
|
|
Where GetTickCount() and the performance counter get their time from varies depending on the
hardware but neither are affected to the system time.
There's a white paper from microsoft about certain motherboards with a bug that affects the
performance counter (it jumps ahead 2 or 4 seconds occasionally) but I can't find it at the
moment. Athlon boards I think...
Mark
|
|
|
|
|
Good point! Thanks Mark!
regards,
George
|
|
|
|
|
Hi...
I need some method to check wether a printer conected to my device or not..I am using GetDefault() function,and also using DeleteDC to delete device context..but it is showing some memory leak with Epson printer.can i use some other function to check for the connected printer.
birajendu
CyberG India
Delhi
India
|
|
|
|
|
|
|
I have drawn sqaure n circle in VC++ . and the requirement is wen i press space bar the colour of the square n circle shud change.
|
|
|
|
|
|
I have drawn sqaure n circle in VC++ . and the requirement is wen i press space bar the colour of the square n circle shud change.
|
|
|
|
|
Add an event handler for keys .. e.g. WM_KEYDOWN or WM_KEYUP whichever you require..
In the event handler check the keycode provide to be of space bar.. set the colors to whatever you want .. i know the answer is a little vague but so was the question :P.. Look into the MSDN for WM_KEYDOWN or WM_KEYUP for specific handling!
|
|
|
|
|
thanks for the help . i know that the event is WM_KEYDOWN but main thing is wat code shud i write to change the colour . i know the key events. please let me knw if u knw this
|
|
|
|
|
cshah2 wrote: but main thing is wat code shud i write to change the colour
Set the new color in your respective member variable and trigger a redraw
You did draw them before, so erase the screen, redraw, but take the color from the color-member-variable mentioned above).
"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation."
-- Caius Petronius, Roman Consul, 66 A.D.
|
|
|
|