Re: Timing your loops



Sleep permits 0 as a parameter. Second sentence describing that parameter in MSDN: "Specify zero (0) to indicate that this thread should be suspended to allow other waiting threads to execute."

Anyway, my apologies to you. It's just that I see people doing this so very, very, very often, and every once in a while I just get fed up. It was more of an "aargh, another one has fallen into the trap!" and not a "you idiot, how could you do something so stupid!"

What you could do is try switching your app from an active to a passive paradigm. Instead of taking a 'greedy' approach that uses up as much CPU time as possible unless you remember to stop it, have you considered an approach whereby you generally do nothing, but occasionally you'll render a frame? Set up a Timer object to fire off every 30ms or so, and when it fires, render&present. Providing your timer-handling code takes less than 30ms to execute, your app should go back to sleep between frames.

I'm not much of a .NET person yet, so yes, I don't really know the best answer to your question. I wasn't sure whether to try and hazard a guess at the things I only half know about and potentially mislead you, or to stick to the things I /do/ know about (like CPU percentages), but you've managed to persuade me to answer as best I can with my limited knowledge. Andy Dunn (the ZMan) is probably the best person to ask for an authoritative answer.

Regarding your second original question: there should be no issues with it, beyond the simple fact that rendering four windows will mean four render passes and presents. If this is for a 3D editor or something, consider faking the four windows by using one D3D window and drawing your own splitter bar over the top of it.

- Richard

P.S. If you expect newsgroups to be 'naturally' kind and helpful, you must be fairly new to the net... many of them are famous for the levels of vitriol and venom bandied about within :-)

Daniel wrote:
Aside from being patronising and rude with the caps you have not answered my question regarding using sleep, also regarding the best way to run my render loop.

i have seen other apps that i am trying to emulate and while running their cpu power is 2% usage in task manager. I want the same. As they can achieve this i CAN use this as a measurement since my app should do the same. By your reckoning why dont all apps that are presently running use 100%? After all they are running and while doing nothing are allocated all the cpu power left....mustn't be left for a rainy day after all. When i sleep my thread i get my cpu power to 0-1% but i want it slightly higher but i cant sleep by 0.5 as it requires an int. I know there must be a better way such as rendering at 33fps and int he extra time saves leaving the cpu alone thus dropping the %. To test it via opening one app and another and seeing is there any slow down? no ..good, ok next two apps is to be honest rediculous. I would have appreciated my question answered not sarcastic remarks. I only presume you don't know how to answer the question in which case a simple 'the taskmanager is not best to guage cpu power, try this way' etc etc.

I appreciate that you did take time to answer but besides making me feel stupid you have not helped, not really the nature of a newsgroup i feel.

"Richard Fine [DXMVP]" <rfine@xxxxxxxx> wrote in message news:%235xJBxmeGHA.536@xxxxxxxxxxxxxxxxxxxxxxx
DON'T USE THE TASK MANAGER CPU PERCENTAGE TO GAUGE THE CPU POWER YOU'RE USING!

If you want to target, say, 50% CPU usage, what exactly do you expect the system to do with the remaining 50%? Keep it in a box for a rainy day? :-)

CPU percentages are /only/ useful (and even then, not /very/ useful) for comparing the CPU timeslice assignment of two active apps running simultaneously. They are /not/ useful for gaining any kind of absolute measure of the power you're using. If nothing else is going on on the system, Windows will automatically assign as much CPU time to your app as it has spare. 100% of the CPU doesn't mean that your app is /demanding/ that much attention, it just means that the scheduler is /giving it/ that much attention.

If you want to test this kind of thing, decide upon your target load in terms of applications (e.g. you want to be able to run Word and Doom3 while your app is open with no noticable slowdown) and test it that way.

- Richard

Daniel wrote:
While windowed it uses 100% cpu power which i dont mind and by using application.doevents it doesnt lock out the system. However i would rather it not use so much cpu power on client machines.


.



Relevant Pages

  • Re: Timing your loops
    ... loops it updates every iteration causing cpu usage. ... And yes i do need multiple separate windows. ... However all this said if letting the app suck 100% isn't actually a bad ... all the cpu power left....mustn't be left for a rainy day after all. ...
    (microsoft.public.win32.programmer.directx.managed)
  • Re: processor time allocation
    ... When an app is doing IO it does NOT show up in the task manager as process ... simply stating that my process is not getting cpu time really doesn't give ... > perfectly fine using Sleep to obtain a near 20 Hz frequency. ... > Which is that my App is CPU starved and windows wont give my app more than ...
    (microsoft.public.vc.mfc)
  • Re: Timing your loops
    ... also regarding the best way to run my render ... cpu power is 2% usage in task manager. ... this i CAN use this as a measurement since my app should do the same. ... When i sleep my thread i ...
    (microsoft.public.win32.programmer.directx.managed)
  • Re: Timing your loops
    ... DON'T USE THE TASK MANAGER CPU PERCENTAGE TO GAUGE THE CPU POWER YOU'RE USING! ... If nothing else is going on on the system, Windows will automatically assign as much CPU time to your app as it has spare. ... If you want to test this kind of thing, decide upon your target load in terms of applications and test it that way. ...
    (microsoft.public.win32.programmer.directx.managed)
  • Re: Sleep API function
    ... when I use Sleep in ... "Sleep 0" will yield the CPU to another application/thread if there is one ... normal priority that uses 100% CPU would virtually stop the one at lower ... there's another app waiting for CPU time or not. ...
    (microsoft.public.vb.winapi)

Loading