Core API - danielep71/VBA-Performance_Manager GitHub Wiki
Core API
This page explains the main public API of cPerformanceManager and how the class is intended to be used in normal practice.
The core workflow is built around three members:
StartTimerElapsedSecondsElapsedTime
Core timing model
cPerformanceManager uses a session-bound timing model.
That means a timing operation is a small structured session:
- choose a timing backend
- start a timing session
- run the workload
- read the elapsed time
- optionally inspect state or diagnostics
- optionally capture checkpoints
- clean up environment changes
The three most important members
StartTimer
Starts a timing session and binds the selected method to that session.
cPM.StartTimer [iMethod], [AlignToNextTick]
Default method:
5
ElapsedSeconds
Returns the elapsed time as a numeric Double in seconds.
ElapsedS = cPM.ElapsedSeconds([iMethod])
Use this for:
- benchmark values
- comparisons
- thresholds
- numeric logging
- aggregation
ElapsedTime
Returns the elapsed time as a human-readable string.
Debug.Print cPM.ElapsedTime([iMethod], [ElapsedSecondsIn])
It can also format an already measured numeric elapsed value without taking a second timing sample.
Additional public surfaces
Session / state inspection
T1 As DoubleT2 As DoubleET As DoubleActiveMethodID As IntegerHasActiveSession As BooleanMethodName(ByVal Idx As Integer) As StringStrictMode As Boolean
Execution control / environment
Pause(ByVal dSeconds As Double, Optional ByVal iMethod As Integer = 1)ResetEnvironment()
Time-waster suppression
TW_Turn_OFF(Optional ByVal Except As TW_Enum = TW_Enum.None)TW_Turn_ON()TW_IsActive As BooleanTW_ActiveSessionCount As Long
Diagnostics / benchmark helpers
OverheadMeasurement_SecondsOverheadMeasurement_TextGet_SystemTickIntervalQPC_Get_SystemTickIntervalQPC_FrequencyPerSecondQPC_FrequencyPerSecond_Value
Structured checkpoint / reporting surface
SetRunLabel(ByVal RunLabel As String)RunLabel As StringCheckpoint(ByVal CheckpointName As String, Optional ByVal NoteText As String = vbNullString)CheckpointCount As LongClearCheckpoints()ReportAsArray() As VariantReportAsText() As String
Normal calling sequence
Dim cPM As cPerformanceManager
Dim ElapsedS As Double
Set cPM = New cPerformanceManager
cPM.StartTimer 5
Range("A1:A10000").Value = 1
ElapsedS = cPM.ElapsedSeconds
Debug.Print ElapsedS
cPM.ResetEnvironment
Set cPM = Nothing
Why the class is session-bound
A timing session stores:
- the active timing backend
- the start timestamp
- whether a session is active
- internal state needed for elapsed evaluation
- structured checkpoint / reporting state
This prevents accidental misuse such as starting with one backend and reading with another, and it keeps checkpoint data tied to one timing run.
Recommended safe pattern
Option Explicit
Public Sub Example_CoreAPI_SafePattern()
Dim cPM As cPerformanceManager
On Error GoTo CleanFail
Set cPM = New cPerformanceManager
cPM.StartTimer 5
Worksheets(1).UsedRange.Calculate
Debug.Print "Elapsed: " & cPM.ElapsedTime
CleanExit:
If Not cPM Is Nothing Then
cPM.ResetEnvironment
Set cPM = Nothing
End If
Exit Sub
CleanFail:
Debug.Print "Error " & Err.Number & " - " & Err.Description
Resume CleanExit
End Sub
For structured reporting examples, see Checkpoint and Reporting.