Repository navigation
Measurement Method
Daniele Penza edited this page Dec 5, 2026
·
4 revisions
Every benchmark module in docs/benchmarks/ follows the same steps:
-
Pre-flight check. Before timing, the module counts running
EXCEL.EXEprocesses and GitHub runner jobs (Runner.Worker.exe) and samples CPU load for five seconds. It refuses to run if another Excel is open, a runner job is active, or the CPU averages over 10%. - Same result first. Every variant of a group returns a checksum; a timing is reported only for variants that compute the same result.
- Warm-up, then five timed runs per variant, with the order reversed on every other run (A B C, C B A, ...) so a drift in load hits every variant.
-
Median of the five runs, timed with
QueryPerformanceCounter; the spread(slowest - fastest) / medianflags noisy groups. - Unedited output. The sheet each run writes is committed as is.
| Run | Scope | Module |
|---|---|---|
| A | Language basics | M_BookBench.bas |
| B | Numbers and dates | M_BookBench2.bas |
| C | Cross-check of run A with VBA Performance Manager | M_BookBench_PM.bas |
| D | Strings | M_BookBench3.bas |
| E | Arrays and collections | M_BookBench4.bas |
| F | Files, classes, binding |
M_BookBench5.bas, M_BookBench5_Early.bas, cBench5Item.cls, cBench5Node.cls
|
| G | Windows API on 64-bit Office | M_BookBench6.bas |
| H | CSV import and export, 10 MB UTF-8 file | M_BookBench7.bas |
| I | Working with the sheet: cells, formatting, Select, clipboard, row deletes, whole columns |
M_BookBench8.bas |
| J | Lookups by table size, Evaluate, Calculate, volatile UDFs, state guards with formulas and events |
M_BookBench9.bas, cBench9Events.cls
|
| K | Growing arrays, Debug.Print and the status bar, IIf, loop conditions, objects created in a loop |
M_BookBench10.bas |
- β Cross-checked. VBA Performance Manager reproduced run A within 4-8% in absolute time and within 2% in ratio for the three workloads of 14-700 ms.
β οΈ Short workloads are unreliable throughApplication.Run. One dispatch costs about 24 us: a 0.026 ms workload measured 0.058 ms through it. Time blocks of at least about 10 ms, or subtract a baseline measured on an emptySub.β οΈ One machine, except run K. Ratios travel well between machines; absolute times do not. Run K ran on two machines, both with the VBA editor open: a forced run on the usual one, while another Excel and a runner job were busy, and a clean run on a second one (Excel build 20527). Only the ratios above 2x that both runs agree on are quoted.β οΈ A clean workbook. Volatile cells anywhere in the workbook change the cost of every write: the first run J left 500 volatile UDF cells on a scratch sheet, and two of its groups had to be measured again.- π§ͺ Figures marked estimate extrapolate a measured growth rate to a larger size.
| Clock | Smallest step observed | Cost of one read | Use |
|---|---|---|---|
Timer |
3.9 ms (1/256 s); resets at midnight | too coarse to measure | β benchmarks |
timeGetTime |
1 ms | too coarse to measure | β short benchmarks |
System tick (GetTickCount) |
15.6 ms | too coarse to measure | β benchmarks |
QueryPerformanceCounter |
0.1 us (10 MHz) | about 1.7 us (an API call) | β benchmarks |
#If VBA7 Then
Private Declare PtrSafe Function QueryPerformanceCounter Lib "kernel32" (ByRef lpCount As Currency) As Long
Private Declare PtrSafe Function QueryPerformanceFrequency Lib "kernel32" (ByRef lpFrequency As Currency) As Long
#Else
Private Declare Function QueryPerformanceCounter Lib "kernel32" (ByRef lpCount As Currency) As Long
Private Declare Function QueryPerformanceFrequency Lib "kernel32" (ByRef lpFrequency As Currency) As Long
#End If
Public Function SecondsFor(ByVal Repeats As Long) As Double
Dim f As Currency, t0 As Currency, t1 As Currency, i As Long
QueryPerformanceFrequency f
QueryPerformanceCounter t0
For i = 1 To Repeats
' code under test: repeat it until the block takes at least about 10 ms
Next i
QueryPerformanceCounter t1
SecondsFor = (t1 - t0) / f ' the Currency scale factor cancels out
End FunctionTip
Never time one short operation: a single clock read costs more than most VBA statements. Time a loop of many, and divide.
- Import the module from
docs/benchmarks/into an empty macro-enabled workbook (for run F, import the two.clsfiles first; for run J,cBench9Events.cls). - Close every other Excel window and run its entry point:
BENCH_RunAll,BENCH2_RunAll...BENCH10_RunAll, orBENCH5E_RunAll(needs a reference to Microsoft Scripting Runtime). - Save the sheet it writes as a new results file. Never edit an old one.
π Figures: Excel 365 (16.0 build 20723) 64-bit, Windows desktop, median of 5 runs Β· Raw data in docs/benchmarks/
- π Home
- π Measurement Method
Topics
- π Working with Excel
- π¦ Passing Data
- π€ Strings
- π’ Numbers and Dates
- π Searching, Sorting and Collections
- π§© Calls, Classes and Binding
- π Files and CSV
- πͺ Windows API on 64-bit Office
Reference
β οΈ Correctness Traps- π§° Skill Rules