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 › Processing vs. openframeworks speed test
Pages: 1 2 
Processing vs. openframeworks speed test (Read 6663 times)
Re: Processing vs. openframeworks speed test
Reply #15 - Feb 14th, 2010, 8:51am
 
Has anyone here tried OPENCL for Java?
Re: Processing vs. openframeworks speed test
Reply #16 - Feb 14th, 2010, 10:05am
 
I got 19.7fps for davbol's displaylist version... up from 12.5fps from my original sketch. Not bad but still not up to OF's 42fps (which is "out of the box" performance). You do have to do some fairly complex stuff (from my point of view) to get this improvement.
Re: Processing vs. openframeworks speed test
Reply #17 - Feb 14th, 2010, 10:12am
 
if you are trying to compared only 2 frameworks, yes go ahead and use that. it works. still is not a fair test at all. OF only runs on opengl so it uses the gpu (it runs on vertex arrays) and you compare against cpu performance and immediate mode. to really get a speed test (if that is what you are really interested in), you would need to go down and write an app just as equal as OF and then compare.
let me tell you, it will be slower anyway.
so why do all of us still use processing/java and not c++ hmm...


as for opencl. yes. http://processing.org/discourse/yabb2/num_1256926472.html
Re: Processing vs. openframeworks speed test
Reply #18 - Feb 14th, 2010, 11:43am
 
Yes, they definitely both have strengths and weaknesses.... I will be using both in future, depending on the specific thing I am trying to achieve.... I was just curious to see if, without much technical knowledge or tweaking, my programs would run much  faster "out of the box" in OF - as I am an artist starting to work with programming, and don't have much programming background to tweak things...
Re: Processing vs. openframeworks speed test
Reply #19 - Feb 14th, 2010, 12:56pm
 
..because C++ is hell nasty.

..and for some reason even Microsoft Visual C++ is freakin' useless (refactoring, anyone?).

I was called in at the last minute to work on a project which I did with OF, having not really used C++ since a couple of months using it at uni, and it bit my arse over and over with having to maintain header files and 'code' files with their definitions and declarations.

After just having played a little with Eclipse for Java which was able to automatically extract segments of code as methods with everything working, it was a bit of a rude shock.  Cheesy
Re: Processing vs. openframeworks speed test
Reply #20 - Feb 16th, 2010, 10:08am
 
Try this.. I got it to run at around 370fps on my macbook pro.  Could probably be faster if converted into a VBO.

Code:
import processing.opengl.*; 
import javax.media.opengl.GL;

int numparticles =10000;
PGraphicsOpenGL pgl;
GL gl;
particle[] particles;

void setup()
{

 size(500, 500, OPENGL);
 background(255);

 noStroke();

 //smooth();
 pgl = (PGraphicsOpenGL) g;
 gl = pgl.gl;
 gl.setSwapInterval(0);
 gl.glEnable(gl.GL_POINT_SMOOTH);

 frameRate(2000);

 particles = new particle[numparticles];
 for(int i=0; i<numparticles; i++)

 {

   particles[i] = new particle(random(450, width-20), random(450, height-20), 10, 10, 5, 0.9,

   color(0, 0, 0, 255));

 }

}

void draw()

{

 background(255);

 pgl.beginGL();
 gl.glPointSize(8.0f);
 gl.glBegin(gl.GL_POINTS);
 for(int i=0; i<numparticles; i++) {
   particles[i].render();
 }
 gl.glEnd();

 for(int i=0; i<numparticles; i++)

 {

   particles[i].collide();

   particles[i].move();


   particles[i].xspeed*=particles[i].dampfactor;

   particles[i].yspeed*=particles[i].dampfactor;

 }
 pgl.endGL();
 if (frameCount%30==0) println(frameRate);

}

class particle

{

 float xpos, ypos;

 float xspeed, yspeed;

 int ewidth;

 int eheight;

 float speedfactor;

 float dampfactor;

 color col;



 particle(float x, float y,int ew, int eh, float sf, float df,color c)

 {

   xpos=x;

   ypos=y;

   xspeed=0;

   yspeed=0;

   ewidth=ew;

   eheight=eh;

   speedfactor=sf;

   dampfactor=df;

   col=c;

 }



 void collide()

 {

   int leftcols = (int)random(0, eheight+1);

   int rightcols=(int)random(0, eheight+1);

   int topcols= (int)random(0, ewidth+1);

   int botcols= (int)random(0, ewidth+1);



   xspeed+= (leftcols-rightcols)/speedfactor;

   yspeed+= (topcols-botcols)/speedfactor;

 }

 void move()

 {

   xpos+=xspeed;

   ypos+=yspeed;

   if (xpos+ewidth> width || xpos-ewidth<0) xspeed*=-1;

   if (ypos+eheight> height || ypos-eheight<0) yspeed*=-1;

 }



 void render()
 {
   gl.glColor3f(red(col),green(col),blue(col));
   gl.glVertex2f(xpos,ypos);
 }

}
Re: Processing vs. openframeworks speed test
Reply #21 - Feb 16th, 2010, 6:45pm
 
Wow.... 245fps on my machine. Can you explain what is going on here? I presume you are getting the GPU to do the rendering directly? How exactly does it work?
Re: Processing vs. openframeworks speed test
Reply #22 - Feb 16th, 2010, 7:27pm
 
The processor is still doing a bit of the work on the physics but we're making direct OpenGL calls to the video card to display it.  It's also been organized more efficiently for sending the video data, but it's still sending all the vertex and color data to the card each time.  One step further would be a Vertex Array, which is what I believe is posted below.  The positions are updated in the float buffer and then sent to the card.  I got around 480fps with this one.

Take that OF  Wink   Of course, at this point, you're loosing a bit of the simplicity that makes Processing so appealing.  But at least you have that flexibility - you can get hard core if you need too.

I'm trying to read up more on how to do a VBO (Vertex Buffer Object) and how it is different than the code below. I'm not completely sure how to do it.  Perhaps someone else could post an example, but I'll try to figure it out and post if I do (I'd like to know myself).

Code:
import processing.opengl.*; 
import javax.media.opengl.GL;
import java.nio.*;

int numparticles =10000;
PGraphicsOpenGL pgl;
GL gl;
particle[] particles;
float[] xy;
float[] rgb;
FloatBuffer f;
FloatBuffer c;

void setup()
{

 size(500, 500, OPENGL);
 background(255);
 hint(DISABLE_DEPTH_TEST);
 hint(DISABLE_OPENGL_ERROR_REPORT);

 noStroke();

 //smooth();
 pgl = (PGraphicsOpenGL) g;
 gl = pgl.gl;

 gl.glEnable(gl.GL_POINT_SMOOTH);
 gl.glPointSize(8.0f);

 gl.setSwapInterval(0); //tells it not to sync with the screen refresh rate
 frameRate(2000);

 particles = new particle[numparticles];
 for(int i=0; i<numparticles; i++)

 {

   particles[i] = new particle(random(450, width-20), random(450, height-20), 10, 10, 5, 0.9,

   color(0, 0, 0, 255));

 }
 initParticles();
}

void draw()

{

 background(255);

 pgl.beginGL();
 gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
 gl.glEnableClientState(GL.GL_COLOR_ARRAY);
 gl.glVertexPointer(2,GL.GL_FLOAT,0,f);
 gl.glColorPointer(4,GL.GL_FLOAT,0,c);
 gl.glDrawArrays(GL.GL_POINTS,0,numparticles);  
 gl.glDisableClientState(GL.GL_VERTEX_ARRAY);
 gl.glDisableClientState(GL.GL_COLOR_ARRAY);
 pgl.endGL();

 for(int i=0; i<numparticles; i++)

 {
   particle p = particles[i];
   p.collide();
   p.move();
   p.xspeed*=p.dampfactor;
   p.yspeed*=p.dampfactor;
   xy[i*2]=p.xpos;
   xy[i*2+1]=p.ypos;
 }
 f.put(xy);
 f.rewind();

 if (frameCount%30==0) println(frameRate);

}

void initParticles() {

 xy=new float[2*2*numparticles];
 rgb=new float[2*4*numparticles];
 for(int i=0; i<numparticles; i++) {
   particle p = particles[i];
   float[] cc = {
red(p.col),green(p.col),blue(p.col),alpha(p.col)    };
   xy[i*2]=p.xpos;
   xy[i*2+1]=p.ypos;
   rgb[i*4]=cc[0];
   rgb[i*4+1]=cc[1];
   rgb[i*4+2]=cc[2];
   rgb[i*4+3]=cc[3];
 }
 f = ByteBuffer.allocateDirect(4 * xy.length).order(ByteOrder.nativeOrder()).asFloatBuffer();
 f.put(xy);
 f.rewind();
 c = ByteBuffer.allocateDirect(4 * rgb.length).order(ByteOrder.nativeOrder()).asFloatBuffer();
 c.put(rgb);
 c.rewind();
 rgb = null;
}


class particle

{

 float xpos, ypos;

 float xspeed, yspeed;

 int ewidth;

 int eheight;

 float speedfactor;

 float dampfactor;

 color col;



 particle(float x, float y,int ew, int eh, float sf, float df,color c)

 {

   xpos=x;
   ypos=y;
   xspeed=0;
   yspeed=0;
   ewidth=ew;
   eheight=eh;
   speedfactor=sf;
   dampfactor=df;
   col=c;

 }



 void collide()

 {

   int leftcols = (int)random(0, eheight+1);
   int rightcols=(int)random(0, eheight+1);
   int topcols= (int)random(0, ewidth+1);
   int botcols= (int)random(0, ewidth+1);



   xspeed+= (leftcols-rightcols)/speedfactor;
   yspeed+= (topcols-botcols)/speedfactor;

 }

 void move()

 {

   xpos+=xspeed;
   ypos+=yspeed;

   if (xpos+ewidth> width || xpos-ewidth<0) xspeed*=-1;

   if (ypos+eheight> height || ypos-eheight<0) yspeed*=-1;

 }

}
Pages: 1 2