Time Waster Suppression - danielep71/VBA-PERFORMANCE_MANAGER GitHub Wiki

Time-Waster Suppression

This page explains how cPerformanceManager manages shared Excel time-waster suppression.

In this class, “time-wasters” refers to Excel Application behaviors that often add noise, latency, or unnecessary overhead during heavy procedures and during performance measurements.

The important point is this:

TW suppression is useful both for cleaner benchmark runs and for improving performance in ordinary Excel/VBA procedures even when no elapsed-time measurement is being taken.

What belongs to this page

This page focuses on:

  • TW_Turn_OFF
  • TW_Turn_ON
  • TW_IsActive
  • TW_ActiveSessionCount
  • TW_Enum

The TW flags

Public Enum TW_Enum
    None = 0
    ScreenUpdating = 1
    EnableEvents = 2
    DisplayAlerts = 4
    Calculation = 8
    Cursor = 16
End Enum

These values are used as a bitmask.

Why TW suppression exists

Excel application behaviors can add substantial overhead through:

  • screen repainting
  • event firing
  • alert prompts
  • calculation churn
  • cursor updates

Sometimes you want that overhead in the measurement because it reflects the real user path. Sometimes you want to suppress it to understand the workload itself. And sometimes you want to suppress it even without timing anything because the procedure is simply heavy and you want it to run faster.

Shared design

TW suppression cannot be managed naively per object because the underlying Application settings are global to Excel.

That is why the class participates in a shared manager model through the required companion module.

TW_Turn_OFF

Starts or updates this instance’s participation in shared TW suppression:

cPM.TW_Turn_OFF [Except]

With no argument, all supported TW settings are suppressed.

TW_Turn_ON

Ends this instance’s participation in shared TW suppression:

cPM.TW_Turn_ON

Because the state is shared, this does not necessarily mean “restore everything immediately.” The shared manager decides the correct resulting Excel state.

Performance-only example

Option Explicit

Public Sub Example_PerformanceOnly()

    Dim cPM As cPerformanceManager

    Set cPM = New cPerformanceManager

    cPM.TW_Turn_OFF

    Range("A1:A50000").Formula = "=ROW()"
    Application.Calculate

    cPM.TW_Turn_ON
    cPM.ResetEnvironment
    Set cPM = Nothing

End Sub