Processing, week 3

Originally published March 11, 2009.
Information provided in this post may be out of date.

It’s been a week and a half since my Processing, week 2 post and I’m still not done with chapter four, “Time Series.” Oh, well.

I’ve been noticing that my Processing programs use a lot of CPU – about 35% on my dual-core, 2 GHz machine. And that’s for a program which just displays static data, like the one below.

Update: thanks to a helpful suggestion, I was able to decrease CPU usage significantly. To find out how, read the comments section.

Oops, your browser does not have a Java Plug-in. Get the latest Java Plug-in here. Or, if you have Java but can't use the Plug-in, feel free to download the program as an executable jar.

This program, from Visualizing Data, plots some US beverage consumption stats over a period of time. Clicking anywhere within the app switches the subject beverage.

Unless I’m missing something, the excessive CPU usage is due to constant re-draw. The book puts all drawing code within the draw() method which is called repeatedly, up to 60 times per second (by default). Setting the frameRate() to 30 fps improves the matter, but only marginally.

As I was putting in the reference link for draw(), I noticed the documentation indicates its continuous execution can be disabled with noLoop(). That’s great, but has the side effect of disabling key or mouse events.

For now I’m willing to overlook this CPU usage “problem” but I hope the book addresses it soon.