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.

  2 Responses to “Processing, week 3”

  1. Well, if your data is static, you can set the frameRate to 1.
    And using noLoop() doesn’t deactivate events, it is removing the draw() routine which does that. But you can have an empty draw() routine.

  2. Hi PhiLho,

    After reading your comment, I re-read the documentation on noLoop() and found a solution to my problem!

    Well, first, I played around with reducing the frameRate() but I didn’t like how “slowly” the chart changed.

    My solution is to call noLoop() in setup() and then call redraw() in mouseClicked().

    Everything is behaving much more reasonably now. Thank you, thank you, thank you.

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

   
© 2011 And now here's something… Suffusion theme by Sayontan Sinha