PDA

View Full Version : Is this fps correct?



tusharpandey13
03-02-2017, 10:03 PM
I am using OpenTK in vb.net.
I am using elapsedticks to determine how many ticks have elapsed during the updateframe method.
To measure my fps, I set up a stopwatch in my onUpdateFrame method:


Dim s As New Stopwatch
Protected Overrides Sub OnUpdateFrame(e As FrameEventArgs)
s.Start()
Console.Write((s.ElapsedTicks).ToString + " ")
s.Reset()
MyBase.OnUpdateFrame(e)
g.refresh(e.Time)
If s.IsRunning Then s.Stop()
End Sub


My run function is:

g.Run(150.0, 150.0)



The output is:
https://i.imgsafe.org/9068aca791.png

Is this correct? Just 1 tick? Or zero?

mhagain
03-03-2017, 02:15 AM
Suggest that you read the documentation on the Stopwatch class: https://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.elapsedticks(v=vs.110 ).aspx

Also be aware that the resolution of the underlying timer may not be sufficient for measuring frametimes.

tusharpandey13
03-03-2017, 02:26 AM
Suggest that you read the documentation on the Stopwatch class: https://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.elapsedticks(v=vs.110 ).aspx

Also be aware that the resolution of the underlying timer may not be sufficient for measuring frametimes.




The Stopwatch measures elapsed time by counting timer ticks in the underlying timer mechanism. If the installed hardware and operating system support a high-resolution performance counter, then the Stopwatch class uses that counter to measure elapsed time. Otherwise, the Stopwatch class uses the system timer to measure elapsed time. Use the Frequency and IsHighResolution fields to determine the precision and resolution of the Stopwatch timing implementation.
-MSDN


I added the following code in the constructor of the gamewindow to check the stopwatch details:


' Display the timer frequency and resolution.
If Stopwatch.IsHighResolution Then
Console.WriteLine("Operations timed using the system's high-resolution performance counter.")
Else
Console.WriteLine("Operations timed using the DateTime class.")
End If

Dim frequency As Long = Stopwatch.Frequency
Console.WriteLine(" Timer frequency in ticks per second = {0}", frequency)
Dim nanosecPerTick As Long = 1000000000 / frequency
Console.WriteLine(" Timer is accurate within {0} nanoseconds", nanosecPerTick)


https://i.imgsafe.org/943ffef915.png

476 ns. Fast enough isn't it?

tusharpandey13
03-03-2017, 02:34 AM
Suggest that you read the documentation on the Stopwatch class: https://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.elapsedticks(v=vs.110 ).aspx

Also be aware that the resolution of the underlying timer may not be sufficient for measuring frametimes.




The Stopwatch measures elapsed time by counting timer ticks in the underlying timer mechanism. If the installed hardware and operating system support a high-resolution performance counter, then the Stopwatch class uses that counter to measure elapsed time. Otherwise, the Stopwatch class uses the system timer to measure elapsed time. Use the Frequency and IsHighResolution fields to determine the precision and resolution of the Stopwatch timing implementation.
-MSDN


I added the following code in the constructor of the gamewindow to check the stopwatch details:


' Display the timer frequency and resolution.
If Stopwatch.IsHighResolution Then
Console.WriteLine("Operations timed using the system's high-resolution performance counter.")
Else
Console.WriteLine("Operations timed using the DateTime class.")
End If

Dim frequency As Long = Stopwatch.Frequency
Console.WriteLine(" Timer frequency in ticks per second = {0}", frequency)
Dim nanosecPerTick As Long = 1000000000 / frequency
Console.WriteLine(" Timer is accurate within {0} nanoseconds", nanosecPerTick)


https://i.imgsafe.org/943ffef915.png

476 ns. Fast enough isn't it?