package me.hammerle.snuviengine.api; public class Timer { private static final int SIZE = 32; private int index = -1; private final long[] times = new long[SIZE]; private long sum = 0; private double callsPerSecond = 0; private long lastTime = System.nanoTime(); public void update() { index = (index + 1) % SIZE; long time = System.nanoTime(); sum -= times[index]; times[index] = time - lastTime; sum += times[index]; lastTime = time; callsPerSecond = (1_000_000_000.0 * SIZE) / sum; } public double getCallPerSecond() { return callsPerSecond; } }