Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Benchmarking Loops per second

Author
Message
Neco
18
Years of Service
User Offline
Joined: 13th Jul 2008
Location: Waterloo, Wisconsin USA
Posted: 12th Dec 2010 01:31
I was wondering if anyone had some code to share that would show how many times per second your main loop is executing.

I've seen some people mention getting really high numbers, etc because of tweaking / decoupling display/logic etc..

But for my simple GUI pasting, etc my numbers seem way low, with a simple integer variable incrementing by 1, with each executing of the main loop.

Just wanted to make sure I wasn't doing it the wrong way, etc. Tried coming up with my own, but failed cause I suck at math and have no idea what I actually need to write and any (if at all) math involved :p

BillR
23
Years of Service
User Offline
Joined: 19th Mar 2003
Location: United States
Posted: 12th Dec 2010 04:30 Edited at: 12th Dec 2010 04:33
The easiest way is to use screen fps()
set cursor 0,0
print screen fps()

frames per second will display in the upper left corner of the screen

for max program speed use
Neco
18
Years of Service
User Offline
Joined: 13th Jul 2008
Location: Waterloo, Wisconsin USA
Posted: 12th Dec 2010 17:31
I'm not interested so much in the FPS, I'm interested in how many times my main loop is being executed per second.

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 12th Dec 2010 17:32
As long as you SYNC once per loop, they mean the same thing.

Neco
18
Years of Service
User Offline
Joined: 13th Jul 2008
Location: Waterloo, Wisconsin USA
Posted: 12th Dec 2010 17:37 Edited at: 12th Dec 2010 17:40
I see...

So, basically if I wanted to see it pushing a really high number of Loops/ps I'd have to decouple the display from other programming logic?

Another somewhat related question.. Since I've just been playing around with some things.

I've noticed when I set Vsync on (caps @ 60hz) and move my window It'll blank out (blue) and in general kind of have that laggy feel as the window is redrawn.

When I turn off Vsync but cap the Sync @60hz, the window freezes with the actual screen image being rendered, and it is virtually redrawn lag-free. Why is that?


What are considered "best practice" methods of setting up your display mode? I'm not opposed to turning Vsync off, but then I wonder about any potential screen tearing (false concern?) even if I'm capping the sync rate.

I suppose the overall goal I want to accomplish (in any program I write) would be to allow it to run flat out as fast as it can, but at the same time, keep it synced to the users refresh rate and prevent tearing, etc.. I am guessing that is where the decoupling of the display loop would come in?

And.. if you can point to any good discussions that address these kinds of topics that would probably save me from more annoying questions

KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 12th Dec 2010 21:42
Decoupling the display loop is helpful. In your logic loop though you don't necessarily have to run it flat out. As long as it always runs at least once every time the display loop runs you are in good shape. Anything more than that is a bonus and helps to smooth the look and feel of your app.

One thing you can do to prevent your app from consuming all available CPU power all the time, is introduce a small wait in the logic loop. If you use the NICE WAIT command from IanM's Matrix1Utils, then it will give back that amount of CPU time to Windows. You can adjust that amount of time by using a variable and setting it only if your program has the processing time to spare.

Neco
18
Years of Service
User Offline
Joined: 13th Jul 2008
Location: Waterloo, Wisconsin USA
Posted: 12th Dec 2010 21:56
Yes, I had planned to incorporate some kind of sleep statement down the road for sure, but right now I don't have much of a logic loop going at all as I'm currently working on getting my asset creation tools up and running (going with XML and then something to compile it over to a saved UDT array). Just got Serna's free XML editor, nifty thing that will take some time to get used to, but should help me out I hope

Care to share your algorithm for deciding how much time to yield back to the rest of the system? I'm definitely interested in such ideas.

DVader
22
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 13th Dec 2010 20:43
Well, as people have said screen fps() is the command you want. If you want a count for your logic and video loops its as easy as `inc loopcount` etc in each of your loops. If you are benchmarking a system I wouldn't think adding in a sleep function would have any value at all. Why reduce your programs potential performance by adding in a sleep command? If you simply want your game to run at a decent speed but give your os a bit more gas then sure, add in a sleep command. Otherwise I can't see much point. As far as an algorithm is concerned, I don't really think many do that, they simply call the sleep command and play about with a setting that works for their game.

http://s6.bitefight.org/c.php?uid=103081
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 13th Dec 2010 21:21
But you have to take into consideration the speed of the player's computer. So an algorithm becomes necessary, but doesn't have to be complicated.

Basically if your Logic loop is running as fast as or slightly faster than your Display loop, then you can't afford to sacrifice the extra processing time. However, if your logic loop is running 4 or 5 times as fast as the Display loop, then a NICE WAIT value of 1 would likely give back a few percentage points to the CPU so it isn't running flat out all the time unnecessarily.

You'll have to decide where that threshold lies. At the moment Worlds Apart Online has such a large and busy logic loop that it can't afford to give up anything. So it runs flat out all the time.

Neco
18
Years of Service
User Offline
Joined: 13th Jul 2008
Location: Waterloo, Wisconsin USA
Posted: 13th Dec 2010 21:39 Edited at: 13th Dec 2010 21:43
I wasn't commenting on the sleep command in terms of benchmarking, but more as a general comment as that was how I feel the original comment on Sleep/Nicewait was being made.

As far as the algorithm - basically I have no real inkling on how to come up with a check so I was looking for an example of how such a check might work.

re: an inc loop count - well that's what I did, and it didn't seem very fast to me (although current I only have one main loop that pastes the GUI images, and then prints the test lines I insert into my display window's array) and while I'm sure its something like 10 - 30 loops per second, its nothing compared to other loop numbers I've seen in the 10's of thousands or 100's of thousands range.

and for a simple loop pasting GUI stuff and printing some text from an array I got the impression that was a little odd.

I do know that the sync rate and/or Vsync plays a part in that though as it will count up much faster with Vsync off and Sync Rate 0


I suppose what would interest me the most, is how I can extrapolate the "increasing too fast to really count" loops per second number I am generating, into a more stable readout of "Average Loops per second" based number, which would be easier for me to read.


I would just like to add, my interest here is purely academic. I don't have any true concerns about performance or optimizations as my program is very early alpha. This is more a case of me trying to satisfy my natural curiosity about how fast it is running, in as concrete (and easy to read) a reference as I can obtain

KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 13th Dec 2010 23:26 Edited at: 14th Dec 2010 00:14
How about this.



Neco
18
Years of Service
User Offline
Joined: 13th Jul 2008
Location: Waterloo, Wisconsin USA
Posted: 13th Dec 2010 23:41
Wish it was commented but... that's very nice

I noticed by tweaking that 1 second interval, I could crush the performance or increase it.


Gonna see if I can figure out how to apply this to my current loop, for fun :p

KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 14th Dec 2010 00:16
Updated with some comments, and a section of code that lets you tweak the game loop performance.

If you change the 1 second interval, you are throwing off the loop counters and only changing the printed display values, not the actual loops.

Neco
18
Years of Service
User Offline
Joined: 13th Jul 2008
Location: Waterloo, Wisconsin USA

Login to post a reply

Server time is: 2026-07-21 07:03:26
Your offset time is: 2026-07-21 07:03:26