Performance
Ce document est disponible en français
What to expect
RD-VBA runs most of a program as compiled code. Each figure below is the time RD-VBA takes for a case of the rdc bench corpus, as a multiple of the time
MS-VBA takes for the same code in Excel: below 1× is faster, above 1× slower. Each badge also gives both times, in milliseconds, on the reference machine
(Excel 16, 64-bit, Windows 11 x64, 12 cores). The figures describe the default settings: the Compiled execution engine and the Debug program
configuration (--configuration, see The shell and the rdc commands).
The RD-VBA figures are measured on every merge. Every case of the corpus is listed, the slowest included. Each case links to its source, and Benchmarks says how to run them on your own machine.
The badge names the CI run that measured the figures. It links to the figures file, whose
run field is that run's address.
Calls
| Case | What it measures | RD-VBA ÷ MS-VBA | Allocated | GC 0/1/2 |
|---|---|---|---|---|
Calls.BenchRecursion |
Recursion: Fib(25), 242,785 short calls |
|||
Calls.BenchProcedureCalls |
A function of the same module, called in a loop | |||
Calls.BenchByRefCalls |
A variable passed ByRef and assigned through the parameter |
|||
Calls.BenchClassMemberCalls |
A member of a class, called through a variable of the class | |||
Calls.BenchInterfaceMemberCalls |
The same member, called through an interface | |||
Calls.BenchStandardLibraryCalls |
N = Len(CStr(I)) + CLng(I) in a loop |
|||
Calls.BenchFactoryCalls |
A factory method of a default instance, a new object on every call | |||
Calls.BenchDefaultInstanceCalls |
A member called on a default instance | |||
Calls.BenchSiblingCalls |
A member that calls a private member of its own class by its bare name | |||
| Total - Calls | The section's cases together: the sum of RD-VBA's times over the sum of MS-VBA's |
Statements
| Case | What it measures | RD-VBA ÷ MS-VBA | Allocated | GC 0/1/2 |
|---|---|---|---|---|
Statements.BenchSetAssignment |
Set D = C of an object variable |
|||
Statements.BenchMemberAssignment |
P.X = I, a property of an object |
|||
Statements.BenchRecordFieldAssignment |
R.X = I, a field of a user-defined type |
|||
Statements.BenchSelectCase |
Select Case I Mod 4 with three branches |
|||
Statements.BenchConditions |
If, ElseIf and Do While conditions: comparisons joined with And |
|||
Statements.BenchMidStatement |
The Mid$ statement: Mid$(S, 1, 1) = "r" |
|||
Statements.BenchOnErrorResumeNext |
A loop under On Error Resume Next, dividing by zero one time in ten |
|||
| Total - Statements | The section's cases together: the sum of RD-VBA's times over the sum of MS-VBA's |
Arrays
| Case | What it measures | RD-VBA ÷ MS-VBA | Allocated | GC 0/1/2 |
|---|---|---|---|---|
Arrays.BenchArrayFillAndSum |
Writing, then reading, every element of a Long array |
|||
Arrays.BenchVariantArray2D |
A 2-D Variant array, every element doubled |
|||
Arrays.BenchVariantHeldArray2D |
The same, with the array held in a Variant, as V = Range(...).Value gives it |
|||
| Total - Arrays | The section's cases together: the sum of RD-VBA's times over the sum of MS-VBA's |
Strings
| Case | What it measures | RD-VBA ÷ MS-VBA | Allocated | GC 0/1/2 |
|---|---|---|---|---|
Strings.BenchStringAssignment |
A String assigned in a loop |
|||
Strings.BenchStringConcatenation |
S = S & "x", a string growing by one character at a time |
|||
Strings.BenchStringComparison |
Short strings joined and compared | |||
Strings.BenchStringBuilding |
A line of numbers written as text, with a separator between each | |||
Strings.BenchStringArguments |
Strings passed to a procedure, by value and by reference | |||
| Total - Strings | The section's cases together: the sum of RD-VBA's times over the sum of MS-VBA's |
Numeric
| Case | What it measures | RD-VBA ÷ MS-VBA | Allocated | GC 0/1/2 |
|---|---|---|---|---|
Numeric.BenchLongCounterDoubleSum |
S = S + I with a Long counter and a Double sum |
|||
Numeric.BenchDoubleSum |
The same loop over Double values |
|||
Numeric.BenchLongArithmetic |
Long arithmetic, kept in range with Mod |
|||
Numeric.BenchVariantSum |
The same loop with every operand a Variant |
|||
Numeric.BenchCurrencyAndDate |
A Currency sum and a Date advanced a thousandth of a day each time |
|||
Numeric.BenchVariantTypedMix |
A Long and a Double added into a Variant sum |
|||
| Total - Numeric | The section's cases together: the sum of RD-VBA's times over the sum of MS-VBA's |
Variables and parameters
| Case | What it measures | RD-VBA ÷ MS-VBA | Allocated | GC 0/1/2 |
|---|---|---|---|---|
Slots.BenchWideActivations |
A call with six typed parameters and four locals | |||
Slots.BenchModuleVariableLoop |
A module variable, read and written each time round | |||
Slots.BenchLocalVariableLoop |
The same loop over a local variable | |||
Slots.BenchStaticVariableLoop |
The same loop over a Static local |
|||
Slots.BenchCurrencySum |
A Currency sum |
|||
Slots.BenchBooleanFlag |
A Boolean flag flipped and tested each time round |
|||
| Total - Variables and parameters | The section's cases together: the sum of RD-VBA's times over the sum of MS-VBA's |
Standard library
Each case calls one function 100,000 times, with the arguments shown.
| Case | What it measures | RD-VBA ÷ MS-VBA | Allocated | GC 0/1/2 |
|---|---|---|---|---|
StdLib.BenchCLng |
CLng(X) of a Double |
|||
StdLib.BenchCDbl |
CDbl(I) of a Long |
|||
StdLib.BenchCStr |
CStr(I) of a Long |
|||
StdLib.BenchVal |
Val(S) of "123.5" |
|||
StdLib.BenchLen |
Len(S) of a String |
|||
StdLib.BenchLeft |
Left$(S, 2) |
|||
StdLib.BenchMidFunction |
Mid$(S, 4, 3) |
|||
StdLib.BenchInStr |
InStr(S, "V") |
|||
StdLib.BenchReplace |
Replace(S, "-", "_") |
|||
StdLib.BenchTrim |
Trim$(S) |
|||
StdLib.BenchUCase |
UCase$(S) |
|||
StdLib.BenchStrComp |
StrComp(S, "rd-vba", vbTextCompare) |
|||
StdLib.BenchAsc |
Asc(S) |
|||
StdLib.BenchChr |
Chr$(65 + I Mod 26) |
|||
StdLib.BenchFormat |
Format$(D, "0.00") |
|||
StdLib.BenchIsNumeric |
IsNumeric(S) of "123.5" |
|||
StdLib.BenchIsEmpty |
IsEmpty(V) of an Empty Variant |
|||
StdLib.BenchVarType |
VarType(V) of a Variant holding a Double |
|||
StdLib.BenchTypeName |
TypeName(V) of the same |
|||
StdLib.BenchAbs |
Abs(-I) |
|||
StdLib.BenchRound |
Round(D, 2) |
|||
StdLib.BenchSqr |
Sqr(I) |
|||
StdLib.BenchInt |
Int(D) |
|||
StdLib.BenchDateAdd |
DateAdd("d", 1, T) |
|||
StdLib.BenchYear |
Year(T) |
|||
StdLib.BenchNow |
Now |
|||
StdLib.BenchUBound |
UBound(A) of an array |
|||
| Total - Standard library | The section's cases together: the sum of RD-VBA's times over the sum of MS-VBA's |
Excel automation
These cases call Excel's object model late-bound from VBA. MS-VBA runs the same code from a second Excel instance, so both sides cross a process boundary. They need Excel, so they are measured in the reference run only: their badges give the reference run's date instead of a live figure. Their source is on the Excel automation page.
| Case | What it measures | RD-VBA ÷ MS-VBA |
|---|---|---|
| Block of 1,000 × 10, read | V = Range(...).Value |
|
| Block of 1,000 × 10, pass | The loop over V(R, C), no call to Excel |
|
| Block of 1,000 × 10, write | Range(...).Value = V |
|
| Block of 1,000 × 10, total | Read, pass and write | |
| Cell by cell, 1,000 × 10 | 10,000 cells, a get and a put each | |
| Block of 100,000 × 10, read | V = Range(...).Value |
|
| Block of 100,000 × 10, pass | The loop over V(R, C), no call to Excel |
|
| Block of 100,000 × 10, write | Range(...).Value = V |
|
| Block of 100,000 × 10, total | Read, pass and write | |
| Total - Excel automation | The section's cases together, each block by its total row: the sum of RD-VBA's times over the sum of MS-VBA's |
Every call to Excel's object model crosses from the program's process to Excel's and back, in MS-VBA and in RD-VBA. A crossing costs far more than the work most calls do, so the number of calls decides how long the code takes: the cell-by-cell case calls Excel four times a cell, 40,000 times in all, while a block is read in four calls and written in four.
How the figures are measured
- The reference run. On the reference machine, MS-VBA and RD-VBA run the corpus in five alternated rounds, MS-VBA first in odd rounds and RD-VBA first in even ones, and the Excel automation cases in the first three of those rounds. Each case runs seven times a round (five for Excel automation), and the figure is the fastest run. The reference run is repeated when the corpus changes.
- Pipeline setup.
rdc benchsets up each run's execution pipeline before it times the run. The RD-VBA times of the reference run include that setup, which the build that recorded them timed; MS-VBA's times have no such step. - On every merge. A Windows build machine runs the corpus in three alternated rounds with two builds of
rdc: the merged one, and the one the reference run used. A case's RD-VBA time is the reference run's, scaled by how the merged build compares with the reference build on that machine. Comparing the two builds on one machine keeps that machine's own speed out of the figure. The figures file (bench.json, on thebadgesbranch) names that machine's processor. - Warm-up. Before its timed runs,
rdc benchruns each case untimed until .NET has finished optimizing the code it calls, andrdc bench-msvbaruns each corpus case twice untimed in MS-VBA (Benchmarks). On every merge, both builds warm up, as in the reference run, and each case runs seven times a round. - Each run starts from a collected heap. Before each timed run,
rdc benchcollects the heap, so whether a garbage collection falls inside a run depends only on what that run allocates and keeps. The time of a collection inside a run is part of the figure. - Allocation. For each case,
rdc benchalso gives what its fastest run allocated and the garbage collections of each generation made while it ran (theallocatedandgc 0/1/2columns). On every merge they are recorded for the merged build, and they are the Allocated and GC 0/1/2 columns of the tables. They do not depend on the machine's speed. The Excel automation cases have none. - Totals. A section's total row is the sum of its cases' RD-VBA times over the sum of their MS-VBA times, so a long case weighs more than a short one. Its Allocated and GC 0/1/2 are the sums of the cases'. In the Excel automation section, a block's total row stands for its read, pass and write rows, so only it is summed.
- Resolution.
rdc benchgives times to a tenth of a millisecond, so a case that takes under a millisecond is good to about ±0.05 ms.
Writing code that runs well
- Work with ranges in blocks. Read a range into an array with one
Range(...).Value, work on the array, and write it back with one assignment. The cell-by-cell and block cases above show the difference. - Keep a hot loop's values typed. A
LongorDoubleloop runs faster than in MS-VBA. The same loop overVariantvalues, or over an array held in aVariant, is slower. - See what runs compiled.
rdc compilationlists the procedures that do not run compiled, and what keeps each one in the interpreter. Code in the interpreter is slower than compiled code. - Measure your own code.
rdc benchtimes eachPublic Sub Bench*()of a workspace's standard modules. Run it before and after a change (see The shell and the rdc commands).
See also
ACCUEIL • HOME | ℹ️ BIENVENUE • WELCOME | 🧩 BÂTISSONS • BUILD | RD-VBAL | SDK | 🌐 rubberduckvba.ca