Created
January 8, 2023 12:23
-
-
Save w2sv/c008a8304b7a0008eab5e0a09cef9cb5 to your computer and use it in GitHub Desktop.
Periodically output averaged FPS in processing PApplet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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