Will C++ be faster?

I’m trying to understand the speed issue. I am running Windows 7 64-bit.
I wrote a simple test program (below) that basically blinks the window black and white.
At reasonably high frame rates ( 5 and higher), the color fill is not uniform.

I don’t know how to determine whether this is a limitation of my hardware, or the Processing graphics engine.

Before embarking on what I’m sure would be a arduous time-consuming detour into C++, I am hoping someone can tell me whether I can expect that C++ would perform this task faster with consistent uniformity.

int iColor; 

void setup() 
{ size(1200, 2200); 
  noStroke();  // Don't draw a stroke around shapes
  frameRate(10);
  iColor = 0 ;
}

void draw()    // this whole block repeats at the frameRate
{ color c = color( iColor,iColor,iColor );  // Define color 'c'
  fill(c);  // Use color variable 'c' as fill color
  rect(0,0,1200,2200);
  if( iColor == 0 ){ iColor = 255  ; } else { iColor = 0  ; }
}

Many thanks

Jake Moskowitz

C++ will not make a difference because the issue has nothing to do with the speed the sketch executes. If you think about it you have slower down the sketch by lowering the frame rate anyway.

I am no expert on graphics cards and screen refresh rates but I suspect the problem has little to do with software and hardware and more to do with human perception.

BTW I suggest that you remove your email address from your posts to reduce the risk of spam.

Welcome to the forum :grinning_face_with_smiling_eyes:

If I run this program in Processing

void draw() {
  background(255);
  line(frameCount % width, 0, frameCount % width, height);
}

it’s totally jittery. The opposite of smooth. If I switch to P2D mode it’s much better, but it still drops frames and tears.

Jittery in p5.js too: p5.js Web Editor

With openFrameworks (C++) it never skips a frame. It’s so smooth and pleasant. Similarly smooth with OPENRNDR (JVM based like Processing).

I think it’s not the language but how things are implemented in each framework.

Question: can one enable / disable vertical sync in Procesing?

Thanks for this !

But your program ran perfectly smoothly for me in Processing on a late model Microsoft Surface Book 3 (windows 11). Even when I made it almost full-screen:

void setup(){ size(3000, 2000); }

void draw() 
 { background(255);
   line(frameCount % width, 0, frameCount % width, height);
 }

Happy for you :slight_smile: But I believe one shouldn’t require a late mode Microsoft Surface Book 3 to draw one moving line smoothly :slight_smile: Also, if you have such a high resolution maybe the jittering is not visible because it’s too tiny to notice.

What if it moves faster?

void setup(){ size(3000, 2000); }

void draw() { background(255);
   line((frameCount * 8) % width, 0, (frameCount * 8) % width, height);
 }

and watch for 60 seconds. Is it still smooth?

On the older desktop running Windows 7 64-bit the image was fractured in a rectilinear pattern which I don’t think is typical of limitations of human perception. That pattern did not appear when I tried the program on a late model Microsoft Surface Book 3 (windows 11), but I did see effects likely due to human perception. At frameRate=40, there seemed to be pauses, as if the computer could not keep up with the requested frame rate. FYI the display (internal laptop) spec says “refresh rate” = 59.99 Hz.

No, it is a bit jittery with the factor of 8. Very jittery at 20.

Anyway, thanks for the suggestion, I will be looking into openFrameworks soon. But meantime, I came across Cinder, which seems more closely tied to the specific hardware of the PC and so (if I am understanding correctly) could be expected to be faster ? What do you think ? Or anyone else ?

I wouldn’t say one framework is faster than the other. The thing that really makes the difference is the ability of the programmer. Even when comparing Java and C++. Looking at the forum openFrameworks seems to have a larger and more active community. And it is nice that you can run programs in Desktop, mobile and Raspberry Pi, even if your current program doesn’t need it. A book in case you want to experiment with it. I must say that errors can be more painful to debug in C++. As in the program closing without any message and having no idea why. But it is probably useful to try different languages to have your own impression :slight_smile:

1 Like