Checkpoint and Reporting - danielep71/VBA-PERFORMANCE_MANAGER GitHub Wiki
Checkpoint and Reporting
This page explains the structured checkpoint and reporting features of cPerformanceManager.
These features are useful when one elapsed value is not enough and you want sub-measurements inside a single timing session.
Members covered here
SetRunLabelRunLabelCheckpointCheckpointCountClearCheckpointsReportAsArrayReportAsText
Why this feature exists
Many real procedures are multi-phase.
Examples:
- load data
- transform
- write back
- recalculate
- export
A single elapsed value tells you the total cost. Checkpoints let you break that total into readable sub-measurements.
Session behavior
Checkpoint/report state belongs to the current timing session.
That means:
StartTimerstarts a fresh timing session- a new
StartTimerclears prior checkpoint/report state ClearCheckpointsalso clears the current checkpoint/report state explicitly
SetRunLabel
Stores an optional run label for the current timing session.
cPM.SetRunLabel "ImportWorkflow"
The run label must be set before the first checkpoint is captured in the current session.
RunLabel
Returns the current run label.
Debug.Print cPM.RunLabel
Checkpoint
Captures one named checkpoint inside the active timing session.
cPM.Checkpoint "LoadData"
cPM.Checkpoint "Recalculate", "Full workbook calculation pass"
Each checkpoint stores:
- sequence number
- checkpoint name
- optional note
- delta seconds since the previous checkpoint
- cumulative elapsed seconds since
StartTimer - method metadata
- optional run label
Blank checkpoint names
If you call:
cPM.Checkpoint vbNullString
the class generates a fallback name such as:
Checkpoint 1
CheckpointCount
Returns the number of captured checkpoints.
Debug.Print cPM.CheckpointCount
ClearCheckpoints
Clears the current checkpoint/report state without recreating the object.
cPM.ClearCheckpoints
This resets:
- run label
- checkpoint count
- last checkpoint marker
- report storage
ReportAsArray
Exports the structured checkpoint report as a 2D Variant array.
Arr = cPM.ReportAsArray
Column order:
RunLabelSeqCheckpointNoteMethodIDMethodNameDeltaSecondsCumulativeSeconds
When no checkpoints exist, the function still returns a header-only 2D array.
ReportAsText
Exports the structured checkpoint report as a readable multiline text block.
Debug.Print cPM.ReportAsText
When no checkpoints exist, it returns:
No checkpoints captured.
Practical example
Option Explicit
Public Sub Example_Checkpoints()
Dim cPM As cPerformanceManager
Dim Arr As Variant
Set cPM = New cPerformanceManager
cPM.StartTimer 5
cPM.SetRunLabel "ImportWorkflow"
Range("A1:A10000").Value = 1
cPM.Checkpoint "LoadValues"
Range("B1:B10000").Formula = "=ROW()"
cPM.Checkpoint "WriteFormulas"
Application.Calculate
cPM.Checkpoint "Recalculate", "Full workbook calculation pass"
Debug.Print cPM.ReportAsText
Arr = cPM.ReportAsArray
Worksheets(1).Range("D3").Resize(UBound(Arr, 1), UBound(Arr, 2)).Value = Arr
cPM.ResetEnvironment
Set cPM = Nothing
End Sub
Good practice
- set the run label before the first checkpoint when you need one
- use short, stable checkpoint names
- keep checkpoint notes optional and meaningful
- treat checkpoint data as session-specific
- use
ReportAsArrayfor worksheet/export use - use
ReportAsTextfor quick diagnostics
Error behavior
The class raises when:
Checkpointis called beforeStartTimerSetRunLabelis called after checkpoint capture has already begun in the current session
See also Strict Mode and Error Behavior.