|
Author |
Topic: Re: cpu usage in processing and java? (Read 3526 times) |
|
TomC
|
Re: cpu usage in processing and java?
« on: Jan 22nd, 2005, 4:29pm » |
|
This was a reply to a post which has now been deleted - please don't do this! This board is a great resource for learning from others, but if we all erase our mistakes then nobody can learn from them. Plus it's confusing and it makes me look stupid! What you describe should be quite quick, but there are any number of things that could be slowing it down. To be honest it sounds as if you're not using processing quite how it was intended, maybe you're fighting with it rather than letting it do its job? A few tips - don't use Java2d stuff in Processing if you can help it. Do all your "work" in loop(), you shouldn't need Threads unless you're loading complex stuff off the web or doing a long complex calculation in the background. Do as much as you can in setup() before you enter loop(). Consider using replicate() to copy image pixels to the screen, it might be faster than image() depending on what you're doing. You'll get *far* more constructive help if you post some code...
|
« Last Edit: Jan 24th, 2005, 2:09pm by TomC » |
|
|
|
|
James
|
Re: cpu usage in processing and java?
« Reply #1 on: Jan 24th, 2005, 1:31pm » |
|
thanks for response tom. turned out to be a miscalculation. -james
|
|
|
|
njet
|
Re: cpu usage in processing and java?
« Reply #2 on: Jan 26th, 2005, 2:25pm » |
|
I have been wondering for a while why this code void setup() { size(900,800); background(122); } void loop () { //rect(random(800), random(800), 6,6); } Runs at 93% CPU on a 1GHz Titanium Mac, 512 MB Ram. 93% CPU and nothing is really happening! In a program where I've got loads of objects (arrays with objects doing repeat loops on other arrays of objects etc) all drawing and moving, the CPU is about the same. So it seems to me that Processing is just using CPU to draw the stage and not the main stuff that one is programming. So what's the point of striving to writing a beautiful and effective code if resizing the applet by 100 pixels is going to be much more effective. (well, a bit nasty/stupid/lazy comment, but there is a sense of truth in it, innit?) Can somebody explain what is happening? Why are there so many resources used to do almost nothing? Drawing an empty stage! Any tips for better performance? cheers nje'o
|
|
|
|
toxi
|
Re: cpu usage in processing and java?
« Reply #3 on: Jan 26th, 2005, 3:05pm » |
|
hi njet, thanks for double posting your question... processing was not meant to be offering killer performance at fairly large screensizes. it's a prototyping & learning tool and as such is more targeted to provide easy access to core concepts like direct manipulation of the pixel buffer etc. if you think about it, having a window size of 900*800 pixels equals 2.75MB of RAM which has to be copied to the graphics card every single frame. that doesn't seem to be much, but doing this 30 times a second would come to almost 90MB of data. that's a fairly big task even for a fast machine... because processing gives you as user total control over the window's pixels it is impossible to do any automatic selective updates and so limit the number of memory needing to be shifted. so at the end of every loop() the entire pixel buffer is redrawn by default. it doesn't matter that the entire buffer is "empty" in your example (there's no such thing as an empty pixel) - a pixel is a number. there's no difference if the number is 0 or the value of the grey used in your example... which brings me back to my post in that other thread you've asked that question. the technique demonstrated over there can drastically speed up your sketch, depending on the overall size of your window and the area of pixels being updated every frame. but it's only YOU who will know about those things and who will have to keep track of them...
|
http://toxi.co.uk/
|
|
|
fry
|
Re: cpu usage in processing and java?
« Reply #4 on: Jan 26th, 2005, 3:37pm » |
|
to add to that.. at large screen sizes we run into a java limitation in how fast it can move pixels using the method that's in processing (MemoryImageSource). the processing code itself is very minimal, yet is completely dominated by Java code taking all the time to do exactly what toxi explains. someday we'll have opengl support which will be much faster and more usable for large-screen applications.
|
|
|
|
njet
|
Re: cpu usage in processing and java?
« Reply #5 on: Jan 26th, 2005, 11:27pm » |
|
Thanks alot for the answers. They clarify alot. I am trying to understand how graphical programming works. This would be the same in Java then? And probably the same problematic in C++ as well, unless you code with vectors? OpenGL will be fantastic addition to Processing. I guess people are waiting eagerly for that. Any timeframe? Keep up the good work guys. njet
|
|
|
|
|