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

  • SetRunLabel
  • RunLabel
  • Checkpoint
  • CheckpointCount
  • ClearCheckpoints
  • ReportAsArray
  • ReportAsText

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:

  • StartTimer starts a fresh timing session
  • a new StartTimer clears prior checkpoint/report state
  • ClearCheckpoints also 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:

  1. RunLabel
  2. Seq
  3. Checkpoint
  4. Note
  5. MethodID
  6. MethodName
  7. DeltaSeconds
  8. CumulativeSeconds

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 ReportAsArray for worksheet/export use
  • use ReportAsText for quick diagnostics

Error behavior

The class raises when:

  • Checkpoint is called before StartTimer
  • SetRunLabel is called after checkpoint capture has already begun in the current session

See also Strict Mode and Error Behavior.