We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I did a basic test to compare the versions for which PApplet extends Fragment against versions for which PApplet extends Activity. in terms of frame rates.
My test consisted of displaying lots of ellipses, with background() being called at each frame.
As seen in the above pictures, the older version (Release 0239) had as much as 72% more frames than the newer one (Release 0249) for a dot count of 500.
I used the following code:
ArrayList<Dot> dots = new ArrayList<Dot>();
@ Override
public void settings() {
//Call size/fullscreen from here
fullScreen(PConstants.P3D);
}
@ Override
public void setup() {
textSize(displayWidth/20);
}
@ Override
public void draw() {
background(0);
for (Dot dot : dots){
dot.move();
dot.display();
}
noStroke();
fill(150,0,0);
rect(0,0,displayWidth, displayHeight/10);
fill(255);
text("Release 0249: #dots: " + dots.size() + ", frameRate: " + (int)(frameRate), 0, displayHeight/20);
}
@ Override
public void mouseDragged(){
dots.add(new Dot());
}
@ Override
public void mousePressed(){
if (mouseY <= displayHeight/10){
dots.clear();
}else{
dots.add(new Dot(true));
}
}
class Dot {
float x, y;
float speedX, speedY;
int r = MainActivity.randInt(0 , 255);
int g = MainActivity.randInt(0 , 255);
int b = MainActivity.randInt(0 , 255);
Dot(){
x = mouseX;
y = mouseY;
speedX = (mouseX - pmouseX)/5;
speedY = (mouseY - pmouseY)/5;
}
Dot(boolean mousePressed){
x = mouseX;
y = mouseY;
}
void display(){
fill(r,g,b);
ellipse(x, y, displayWidth/30, displayWidth/30);
}
void move(){
accelerate();
checkBounds();
x += speedX;
y += speedY;
}
void checkBounds(){
if (x <= 0){
speedX *= -1;
x = 0;
}else if (x >= displayWidth){
speedX *= -1;
x = displayWidth;
}
if (y <= 0){
speedY *= -1;
y = 0;
}else if (y >= displayHeight){
speedY *= -1;
y = displayHeight;
}
}
void accelerate(){
speedX += MainActivity.randInt(-displayWidth/800, displayWidth/800);
speedY += MainActivity.randInt(-displayWidth/800, displayWidth/800);
}
}
Hopefully the code is formatted well...
Press or drag to create dots. Touch red area to reset. Read red area info to draw conclusions. The same code was used for both versions apart from sketchRenderer() instead of settings() - shouldn't make a difference.
The test above uses dots. But it would be great to test other stuff, like images, lines, pshapes etc. and under different cases (different renderers etc.) It would be great if you could emulate the test and confirm if you reach the same conclusion. Different releases are here:
https://github.com/processing/processing-android/releases
So, assuming my results are correct, my main question is: why are newer releases slower than older ones? Is this related to the fact that older ones extend Activity and newer ones extend Fragment?
Any thoughts appreciated.
Answers
@wit221
I just tried your code and am getting very different results to you. I am guessing you are not using the Processing IDE? I edited it a bit to get it to run from the Processing IDE (as below) (the MainActivity references threw errors and i can't see a need for settings() or the @ Overrides?
I couldn't get 239 to run at all, probably because I am on 3.0.1 and it needs an earlier processing release? But I did try 246, 248 and 249...
249 has a bad bug that just shows a grey screen (reported elsewhere) but 246 and 248 both give me a 58/59 fps for 500 ellipses and even at 1000 ellipses I am still getting about 40 fps. Both much higher than the rates you are getting!
Maybe not using PDE is the issue for you?
Thank for your comment. The disparities in results are interesting.
I am including a different code that is good for working in PDE. Also, it includes the possibility to create triangles, lines, rectangles on top of dots - more ways to compare versions. Again, press the triangle box to reset all triangles - same for other shapes.
Might not be the most efficient code, but as long as the same code is employed on various versions then that doesn't matter.
I tried that code in the PDE and I am getting same results. The reason I had originally used Eclipse is because it is very easy to just change the Processing versions and compare them quickly.
Well, maybe you are getting great results because your device is highly performant - could you tell me what kind of device you tested on? But we can't really reach any conclusion if we only test one version. Maybe for an older version your device would have maintained circa 50 fps for 1000 ellipses, which is 10 higher then the newer versions?
My phone is an LG Leon 4G LTE ... a budget phone with a quad core 1.2GHz processor. I will test again later today or tomorrow with an older version of Processing to see what happens.
I just tested using APDE which is over a year old now so based on an old version of everything! Also tried AIDE using an exported project using an old ( 1 year) processing version. Framerates were 44 for 500 dots and 21 for 1000, for both tests, so for me that means old versions of processing are much slower than new versions. I assume this is due to better opengl in latest release?? Very strange to have this difference between us though. I will still test on my PC later.
I confirm my initial results, unfortunately... Some older versions are slower indeed, but there doesn't seem to be a clear trend. Each version has its peculiarities... The latest version, 0249, handles lines and ellipses the worst of all I have tested, that's for sure.
I have repeated the below three times, each time I got very similar results.
OK... With PC for 500 shapes 239 ie old gives 42 fps for ellipses 59 for rects 43 for triangles and 17 for lines 249 ie latest gives 58/59 for everything except lines which is still 17.
So lines is much worse than everything else .. I will avoid lots of lines!
This is very confusing. Here are my results: