-
Notifications
You must be signed in to change notification settings - Fork 13
Time Measurement Profiling
FPL provides a couple of functions for measuring elapsed time, used for profiling, delta time calculations and timeouts.
Note: These functions are meant for delta measurements only. They are not tied to a calendar date and the starting point is undefined (OS start, system start, etc.).
To query the current calendar date and time, see
Query Date & Time instead.
For the most precise time measurement, use fplTimestampQuery() to capture a fplTimestamp.
A fplTimestamp is an opaque value - it only has meaning when compared against another timestamp.
To get the elapsed time between two timestamps, call fplTimestampElapsed() . It returns the delta in seconds as fplSeconds (a 64-bit double).
// Capture the starting timestamp
start = ();
// ... do some work ...
// Capture the finishing timestamp and compute the delta
finish = ();
elapsed = (start, finish);
("Work took %f seconds\n", elapsed);This is the recommended way to compute frame delta times in a game loop:
last = ();
while (running) {
now = ();
deltaTime = (last, now);
last = now;
// Update the game using deltaTime
}For simple, less precise measurements you can use fplMillisecondsQuery() .
It returns the current system clock in milliseconds as fplMilliseconds (a 64-bit unsigned integer), counted from some fixed but undefined starting point.
start = ();
// ... do some work ...
elapsed = () - start;
("Work took %llu milliseconds\n", elapsed);A number of FPL functions (mutexes, signals, semaphores, etc.) accept a timeout argument expressed as a fplTimeoutValue.
This is a timeout in milliseconds. To wait indefinitely, pass the FPL_TIMEOUT_INFINITE constant.
// Wait at most 500 milliseconds
timeout = 500;
// Wait forever
infinite = ;- Use fplTimestampQuery() / fplTimestampElapsed() when precision matters (profiling, frame delta time).
- Use fplMillisecondsQuery() for simple, coarse measurements where high precision is not required.
- A fplTimestamp value is platform-dependent and must never be interpreted directly - only compare it with fplTimestampElapsed() .
- The starting point of both clocks is undefined, so only the difference between two queries is meaningful.
- Assertion & Debug
- Atomic operations
- Audio functions
- Clipboard functions
- Console functions
- Constants
- Display/Monitor functions
- Dynamic library loading
- Error Handling
- Files/IO functions
- Function macros
- Hardware Infos
- Input types and functions
- Localization functions
- Logging
- Memory Macros
- Memory functions
- Operating system Infos
- Path functions
- Platform functions
- Session Infos
- Settings & Configurations
- Storage class identifiers
- String functions
- Threading and synchronizations routines
- Timing functions
- Video functions
- Window events
- Window functions
- fplARMCPUCapabilities
- fplAudioChannelMap
- fplAudioDeviceID
- fplAudioDeviceInfo
- fplAudioFormat
- fplAudioSettings
- fplColor32
- fplConditionVariable
- fplConsoleSettings
- fplCPUCapabilities
- fplCPUIDLeaf
- fplDateTime
- fplDateTimeCreationResult
- fplDateTimeResult
- fplDisplayInfo
- fplDisplayMode
- fplDynamicLibraryHandle
- fplEndianess
- fplEvent
- fplFileEntry
- fplFileHandle
- fplFilePermissions
- fplFileTimeStamps
- fplGamepadButton
- fplGamepadData
- fplGamepadEvent
- fplGamepadInfo
- fplGamepadInputBinding
- fplGamepadMapping
- fplGamepadSettings
- fplGamepadState
- fplGamepadStates
- fplGraphicsApiSettings
- fplImageSource
- fplInputBackendMask
- fplInputBackendSupport
- fplInputDevice
- fplInputDeviceGuid
- fplInputSettings
- fplInternalConditionVariable
- fplInternalDynamicLibraryHandle
- fplInternalFileEntryHandle
- fplInternalFileHandle
- fplInternalFileRootInfo
- fplInternalMutexHandle
- fplInternalSemaphoreHandle
- fplInternalSignalHandle
- fplInternalThreadHandle
- fplKeyboardEvent
- fplKeyboardState
- fplLogSettings
- fplLogWriter
- fplLogWriterConsole
- fplLogWriterCustom
- fplMemoryAllocationSettings
- fplMemoryBlock
- fplMemoryInfos
- fplMemorySettings
- fplMouseEvent
- fplMouseState
- fplMutexHandle
- fplOpenGLSettings
- fplOSVersionInfos
- fplSemaphoreHandle
- fplSettings
- fplSignalHandle
- fplSpecificAudioSettings
- fplThreadHandle
- fplThreadParameters
- fplTimestamp
- fplVersionInfo
- fplVideoBackBuffer
- fplVideoRect
- fplVideoRequirements
- fplVideoRequirementsVulkan
- fplVideoSettings
- fplVideoSurface
- fplVideoSurfaceOpenGL
- fplVideoSurfaceVulkan
- fplVideoWindow
- fplVulkanSettings
- fplWindowCallbacks
- fplWindowDropFiles
- fplWindowEvent
- fplWindowPosition
- fplWindowSettings
- fplWindowSize
- fplX86CPUCapabilities