[FPS counter saying 980+?]

Just wondering, right now of course there’s nothing really being drawn, just forcing a bar back and forth across the screen to catch lags.
But, it is telling me that the current fps is at 980+?

Here is the method, it’s being called upon the first loop.


    public void updateFPS() {
		currentFPS ++;
        if (System.currentTimeMillis() - start >= 1000) {
            FPS = currentFPS;
            currentFPS = 0;
            start = System.currentTimeMillis();
        }
    }


    public void cycle() {
		updateFPS();
		System.out.println("FPS: "+FPS);
    }

Now I’ve made a couple of projects, and the FPS usually turns out from 20-70 highs of 140, so i’m thinking this is wrong, can someone confirm?
What should the average fps be?
Maximum, minimum, average?

Your FPS method looks fine, so your count should be ok. Since you’re not doing anything, it’s reasonable to have such high fps.

By the way, System.out.println() is really slow. you should just print it just before resetting the FPS counter. You’ll probably see it increasing beyond 980.

What? Only 980? System.out.println("FPS: "+FPS); is bottlenecking your application. Try to only print out the FPS once per second (move it to inside the if-statement in updateFPS()).

Ah, thanks guys, now it’s out printing every second, which as said does improve.
What is better higher fps, or lower?

,<

the higher, the quicker is your update/render loop which is a good thing (you don’t have slow downs). however you’d want to limit it by Thread.sleep or Thread.yield to avoid your application consuming too much cpu (or to ensure it’ll run the same speed in all computers if you’re not using delta Time in your phyiscs/logic)

Well see, it’s not running off of a thread, it’s running by:


		time = new Timer(1, this);
		time.start();

So…
Change that speed to ‘limit’ it, or go in the updateFPS, and limit it.
Or maybe that makes no sense thinking about it ._.

public class FpsTest {
	public static void main(String[] args){
		int fpsCounter = 0;
		long nextUpdate = System.currentTimeMillis() + 1000;
		while(true){
			fpsCounter++;
			if(nextUpdate < System.currentTimeMillis()){
				System.out.println("FPS: " + fpsCounter);
				fpsCounter = 0;
				nextUpdate += 1000;
			}
		}
	}
}

Result:

FPS: 67548648
FPS: 67612529
FPS: 67327150
FPS: 67323088
FPS: 67275675
FPS: 67398851

THIS IS NORMAL! You’re not doing anything, and you have a processor running at somewhere between 2-4 gigahertz. 67 612 529 “FPS” is nothing in this case. The slow part is checking the time (System.currentTimeMillis()).

Example: I have a processor running at about 2.8 GHz (stupid Turbo Boost changing it all the time). It managed about 67.76 million iterations per second. That’s about 41 clock cycles per iteration of the loop. Stop worrying about your FPS already! Only ever worry about it if it’s too low! xD

I thought you had 1,000,000,000 sprites to render with huge AI computations for each of 1,000 entities and still get that FPS ;D

Sorry, did you say something? Well, it’s not 1 billion sprites, but…

@theagentd
thats 4 million sprites :slight_smile: well if the sprite is 2x2 px, 1 billion is possible. (wait it’s only dot!)

There’s only about 2 MILLION (2 000 000) pixels on a 1080p screen, so why would you want 1 000 000 000 SPRITES in the first place? It would take 10 minutes to render a single frame with that many sprites due to a vertex bottleneck. -_-’

Sorry to derail the thread!

I have a 4.0GHz CPU, ran the FPS test = about 80 million FPS 8)

However, only 1 of my cores was being used. So I created 8 threads (for 8 logical cores) = 200-300 million FPS 8)