Skip to content

Instantly share code, notes, and snippets.

@w2sv
Created January 8, 2023 12:23
Show Gist options
  • Save w2sv/c008a8304b7a0008eab5e0a09cef9cb5 to your computer and use it in GitHub Desktop.
Save w2sv/c008a8304b7a0008eab5e0a09cef9cb5 to your computer and use it in GitHub Desktop.
Periodically output averaged FPS in processing PApplet
import processing.core.PApplet;
import com.google.common.collect.EvictingQueue;
public class Sketch extends PApplet{
private final EvictingQueue<Integer> fpsValues = EvictingQueue.create(100);
private int lastFpsOutputSec = -1;
public void draw(){
fpsValues.add((int) frameRate);
int second = second();
if (lastFpsOutputSec != second) {
Timber.i("FPS: %s", fpsValues.stream().mapToInt(Integer::intValue).sum() / fpsValues.size());
lastFpsOutputSec = second;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment