We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Advice on lowering CPU usage
Page Index Toggle Pages: 1
Advice on lowering CPU usage (Read 1187 times)
Advice on lowering CPU usage
Apr 5th, 2007, 9:25pm
 
Hi Everyone,

For better or worse, I have used processing to develop a fairly complicated user interface for my program, all of the controls drawn manually...  It looks and works very well, except for the fact that the CPU is running at around 40-50%  
When I look at other programs using Swing etc. for GUI, they run at hardly anything.

Does any kind person have advice on how I may lower the CPU useage? I don't need any advanced graphics functions (apart from gradient, which only seems to work if I use OPENGL).

Thanks a lot!
C
Re: Advice on lowering CPU usage
Reply #1 - Apr 5th, 2007, 9:52pm
 
Two things: what are you using to measure CPU usage, and also what are you doing in your code?  Posting the relavant part of your code would help.

CPU usage can be misleading because if you really think about it, the CPU is always either at 0% or 100% ...
Re: Advice on lowering CPU usage
Reply #2 - Apr 5th, 2007, 10:03pm
 
Hi,

I'm using Windows, so I just hit ctrl-alt-del and check... it usually seems to be pretty accurate.

My program is far too long to post in this forum - when I say GUI I mean multiple Windows, buttons, etc.  The thing is - when I look at other programs that are equally 'complicated' visually, they almost never incur the same processor cost.  I was hoping that there was something that I could do to lessen the CPU load.

Cheers,
Crispin
Re: Advice on lowering CPU usage
Reply #3 - Apr 6th, 2007, 12:07am
 
One reason might be that processing is going to draw everything over and over every frame by default. You could lower the CPU usage just by not using background() every frame and only redrawing when the user takes some action.
Re: Advice on lowering CPU usage
Reply #4 - Apr 6th, 2007, 10:02am
 
I think one way to speed it up would be to draw the UI into sperate PGraphics instances, and then just image() them onto the main display. Then you only have to actually re-draw parts f the UI if they change, oherwise just copy them to the display.
Re: Advice on lowering CPU usage
Reply #5 - Apr 6th, 2007, 5:20pm
 
Hi Scloopy and JohnG,

Thanks a lot for your advice - I completely overlooked the background() call.  It should be a bit of a pain to implement effectively, but I'm sure it'll help.  If that doesn't work, I might look into your method JohnG.  Off to do some optimizing -

Cheers,
Crispin
Re: Advice on lowering CPU usage
Reply #6 - Apr 7th, 2007, 2:11pm
 
this is what noLoop(), loop(), and redraw() are for. you can also use frameRate() to set the rate lower if you don't need to run at 60 fps.

but if you're building something that's just a ui, put noLoop() inside setup(), then whenever an action is taken with the mouse or whatever, call redraw() which will make draw() happen. or if you need to run the animation for a bit, use loop(), then call noLoop() later.
Page Index Toggle Pages: 1