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 & HelpPrograms › General Performance Tips
Page Index Toggle Pages: 1
General Performance Tips (Read 1009 times)
General Performance Tips
Dec 14th, 2007, 5:31pm
 
What are some general things someone can do to boost overall performance in Processing?  

I have lowered my framerate and this is nice, for example
Re: General Performance Tips
Reply #1 - Dec 17th, 2007, 8:14pm
 
First of all a clever choice of algorithm usually provides the greatest performance boost when programming.

Other than that a general advice (applicable to all languages) is to preload and precalculate as much as possible in setup() and to only put a minium of heavy code inside draw().

What kind of sketches are you coding? Do you experience sluggish drawing/calculations/loading?
Re: General Performance Tips
Reply #2 - Dec 18th, 2007, 1:01am
 
Here's a few:

Use multiplication instead of division (it's faster in most languages - look up why yourself)

Less objects. They make the code easier to understand but ultimately slow things down.

Use switch() instead of many if statements (look up why yourself)

float if you can instead of doubles, ints if you can instead of floats, bytes, etc. Less memory - less work for the PC.

my_variable++ instead of my_variable+=1

my_integer<<1 instead of my_integer*=2 (again, look these up)

ArrayList instead of using arraycopy again and again just to add one to an array (even better - just use a big array in the first place)

OPENGL

Turn off your other applications (and the screensaver)

Increase the maximum available memory in File>Preferences

Avoid unnecessary calculations (eg: you're working out if two circles overlap - so you figure you need to get the distance between the two circle's centers and compare that to the sum of the radiuses of the two circles. Why not just compare the square of the distance against the square of the sum of the two radiuses? You've just saved yourself from doing an expensive Math.sqrt operation to get that distance calculation. Again - you want to compare if two lines intersect - why not check the bounding boxes of the two lines first? You've just saved yourself from two division operations for a couple of lines that are nowhere near each other)

ermm...

There's more but's that's all off the top of my head for now.
Re: General Performance Tips
Reply #3 - Dec 18th, 2007, 6:56pm
 
I found a nice tip sheet over at the docs to Google's new Android framework, of all places --

http://code.google.com/android/toolbox/performance.html

Some of it is a bit over-the-top for desktop Java -- (they are assuming your code is going to run on a seriously resource-constrained mobile device) -- but there are still lots of little things that are easy to do.
Page Index Toggle Pages: 1