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 CI run that measured these figures 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.BenchRecursion Calls.BenchRecursion, allocated Calls.BenchRecursion, collections
Calls.BenchProcedureCalls A function of the same module, called in a loop Calls.BenchProcedureCalls Calls.BenchProcedureCalls, allocated Calls.BenchProcedureCalls, collections
Calls.BenchByRefCalls A variable passed ByRef and assigned through the parameter Calls.BenchByRefCalls Calls.BenchByRefCalls, allocated Calls.BenchByRefCalls, collections
Calls.BenchClassMemberCalls A member of a class, called through a variable of the class Calls.BenchClassMemberCalls Calls.BenchClassMemberCalls, allocated Calls.BenchClassMemberCalls, collections
Calls.BenchInterfaceMemberCalls The same member, called through an interface Calls.BenchInterfaceMemberCalls Calls.BenchInterfaceMemberCalls, allocated Calls.BenchInterfaceMemberCalls, collections
Calls.BenchStandardLibraryCalls N = Len(CStr(I)) + CLng(I) in a loop Calls.BenchStandardLibraryCalls Calls.BenchStandardLibraryCalls, allocated Calls.BenchStandardLibraryCalls, collections
Calls.BenchFactoryCalls A factory method of a default instance, a new object on every call Calls.BenchFactoryCalls Calls.BenchFactoryCalls, allocated Calls.BenchFactoryCalls, collections
Calls.BenchDefaultInstanceCalls A member called on a default instance Calls.BenchDefaultInstanceCalls Calls.BenchDefaultInstanceCalls, allocated Calls.BenchDefaultInstanceCalls, collections
Calls.BenchSiblingCalls A member that calls a private member of its own class by its bare name Calls.BenchSiblingCalls Calls.BenchSiblingCalls, allocated Calls.BenchSiblingCalls, collections
Total - Calls The section's cases together: the sum of RD-VBA's times over the sum of MS-VBA's Total - Calls Total - Calls, allocated Total - Calls, collections

Statements

Case What it measures RD-VBA ÷ MS-VBA Allocated GC 0/1/2
Statements.BenchSetAssignment Set D = C of an object variable Statements.BenchSetAssignment Statements.BenchSetAssignment, allocated Statements.BenchSetAssignment, collections
Statements.BenchMemberAssignment P.X = I, a property of an object Statements.BenchMemberAssignment Statements.BenchMemberAssignment, allocated Statements.BenchMemberAssignment, collections
Statements.BenchRecordFieldAssignment R.X = I, a field of a user-defined type Statements.BenchRecordFieldAssignment Statements.BenchRecordFieldAssignment, allocated Statements.BenchRecordFieldAssignment, collections
Statements.BenchSelectCase Select Case I Mod 4 with three branches Statements.BenchSelectCase Statements.BenchSelectCase, allocated Statements.BenchSelectCase, collections
Statements.BenchConditions If, ElseIf and Do While conditions: comparisons joined with And Statements.BenchConditions Statements.BenchConditions, allocated Statements.BenchConditions, collections
Statements.BenchMidStatement The Mid$ statement: Mid$(S, 1, 1) = "r" Statements.BenchMidStatement Statements.BenchMidStatement, allocated Statements.BenchMidStatement, collections
Statements.BenchOnErrorResumeNext A loop under On Error Resume Next, dividing by zero one time in ten Statements.BenchOnErrorResumeNext Statements.BenchOnErrorResumeNext, allocated Statements.BenchOnErrorResumeNext, collections
Total - Statements The section's cases together: the sum of RD-VBA's times over the sum of MS-VBA's Total - Statements Total - Statements, allocated Total - Statements, collections

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.BenchArrayFillAndSum Arrays.BenchArrayFillAndSum, allocated Arrays.BenchArrayFillAndSum, collections
Arrays.BenchVariantArray2D A 2-D Variant array, every element doubled Arrays.BenchVariantArray2D Arrays.BenchVariantArray2D, allocated Arrays.BenchVariantArray2D, collections
Arrays.BenchVariantHeldArray2D The same, with the array held in a Variant, as V = Range(...).Value gives it Arrays.BenchVariantHeldArray2D Arrays.BenchVariantHeldArray2D, allocated Arrays.BenchVariantHeldArray2D, collections
Total - Arrays The section's cases together: the sum of RD-VBA's times over the sum of MS-VBA's Total - Arrays Total - Arrays, allocated Total - Arrays, collections

Strings

Case What it measures RD-VBA ÷ MS-VBA Allocated GC 0/1/2
Strings.BenchStringAssignment A String assigned in a loop Strings.BenchStringAssignment Strings.BenchStringAssignment, allocated Strings.BenchStringAssignment, collections
Strings.BenchStringConcatenation S = S & "x", a string growing by one character at a time Strings.BenchStringConcatenation Strings.BenchStringConcatenation, allocated Strings.BenchStringConcatenation, collections
Strings.BenchStringComparison Short strings joined and compared Strings.BenchStringComparison Strings.BenchStringComparison, allocated Strings.BenchStringComparison, collections
Strings.BenchStringBuilding A line of numbers written as text, with a separator between each Strings.BenchStringBuilding Strings.BenchStringBuilding, allocated Strings.BenchStringBuilding, collections
Strings.BenchStringArguments Strings passed to a procedure, by value and by reference Strings.BenchStringArguments Strings.BenchStringArguments, allocated Strings.BenchStringArguments, collections
Total - Strings The section's cases together: the sum of RD-VBA's times over the sum of MS-VBA's Total - Strings Total - Strings, allocated Total - Strings, collections

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.BenchLongCounterDoubleSum Numeric.BenchLongCounterDoubleSum, allocated Numeric.BenchLongCounterDoubleSum, collections
Numeric.BenchDoubleSum The same loop over Double values Numeric.BenchDoubleSum Numeric.BenchDoubleSum, allocated Numeric.BenchDoubleSum, collections
Numeric.BenchLongArithmetic Long arithmetic, kept in range with Mod Numeric.BenchLongArithmetic Numeric.BenchLongArithmetic, allocated Numeric.BenchLongArithmetic, collections
Numeric.BenchVariantSum The same loop with every operand a Variant Numeric.BenchVariantSum Numeric.BenchVariantSum, allocated Numeric.BenchVariantSum, collections
Numeric.BenchCurrencyAndDate A Currency sum and a Date advanced a thousandth of a day each time Numeric.BenchCurrencyAndDate Numeric.BenchCurrencyAndDate, allocated Numeric.BenchCurrencyAndDate, collections
Numeric.BenchVariantTypedMix A Long and a Double added into a Variant sum Numeric.BenchVariantTypedMix Numeric.BenchVariantTypedMix, allocated Numeric.BenchVariantTypedMix, collections
Total - Numeric The section's cases together: the sum of RD-VBA's times over the sum of MS-VBA's Total - Numeric Total - Numeric, allocated Total - Numeric, collections

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.BenchWideActivations Slots.BenchWideActivations, allocated Slots.BenchWideActivations, collections
Slots.BenchModuleVariableLoop A module variable, read and written each time round Slots.BenchModuleVariableLoop Slots.BenchModuleVariableLoop, allocated Slots.BenchModuleVariableLoop, collections
Slots.BenchLocalVariableLoop The same loop over a local variable Slots.BenchLocalVariableLoop Slots.BenchLocalVariableLoop, allocated Slots.BenchLocalVariableLoop, collections
Slots.BenchStaticVariableLoop The same loop over a Static local Slots.BenchStaticVariableLoop Slots.BenchStaticVariableLoop, allocated Slots.BenchStaticVariableLoop, collections
Slots.BenchCurrencySum A Currency sum Slots.BenchCurrencySum Slots.BenchCurrencySum, allocated Slots.BenchCurrencySum, collections
Slots.BenchBooleanFlag A Boolean flag flipped and tested each time round Slots.BenchBooleanFlag Slots.BenchBooleanFlag, allocated Slots.BenchBooleanFlag, collections
Total - Variables and parameters The section's cases together: the sum of RD-VBA's times over the sum of MS-VBA's Total - Variables and parameters Total - Variables and parameters, allocated Total - Variables and parameters, collections

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.BenchCLng StdLib.BenchCLng, allocated StdLib.BenchCLng, collections
StdLib.BenchCDbl CDbl(I) of a Long StdLib.BenchCDbl StdLib.BenchCDbl, allocated StdLib.BenchCDbl, collections
StdLib.BenchCStr CStr(I) of a Long StdLib.BenchCStr StdLib.BenchCStr, allocated StdLib.BenchCStr, collections
StdLib.BenchVal Val(S) of "123.5" StdLib.BenchVal StdLib.BenchVal, allocated StdLib.BenchVal, collections
StdLib.BenchLen Len(S) of a String StdLib.BenchLen StdLib.BenchLen, allocated StdLib.BenchLen, collections
StdLib.BenchLeft Left$(S, 2) StdLib.BenchLeft StdLib.BenchLeft, allocated StdLib.BenchLeft, collections
StdLib.BenchMidFunction Mid$(S, 4, 3) StdLib.BenchMidFunction StdLib.BenchMidFunction, allocated StdLib.BenchMidFunction, collections
StdLib.BenchInStr InStr(S, "V") StdLib.BenchInStr StdLib.BenchInStr, allocated StdLib.BenchInStr, collections
StdLib.BenchReplace Replace(S, "-", "_") StdLib.BenchReplace StdLib.BenchReplace, allocated StdLib.BenchReplace, collections
StdLib.BenchTrim Trim$(S) StdLib.BenchTrim StdLib.BenchTrim, allocated StdLib.BenchTrim, collections
StdLib.BenchUCase UCase$(S) StdLib.BenchUCase StdLib.BenchUCase, allocated StdLib.BenchUCase, collections
StdLib.BenchStrComp StrComp(S, "rd-vba", vbTextCompare) StdLib.BenchStrComp StdLib.BenchStrComp, allocated StdLib.BenchStrComp, collections
StdLib.BenchAsc Asc(S) StdLib.BenchAsc StdLib.BenchAsc, allocated StdLib.BenchAsc, collections
StdLib.BenchChr Chr$(65 + I Mod 26) StdLib.BenchChr StdLib.BenchChr, allocated StdLib.BenchChr, collections
StdLib.BenchFormat Format$(D, "0.00") StdLib.BenchFormat StdLib.BenchFormat, allocated StdLib.BenchFormat, collections
StdLib.BenchIsNumeric IsNumeric(S) of "123.5" StdLib.BenchIsNumeric StdLib.BenchIsNumeric, allocated StdLib.BenchIsNumeric, collections
StdLib.BenchIsEmpty IsEmpty(V) of an Empty Variant StdLib.BenchIsEmpty StdLib.BenchIsEmpty, allocated StdLib.BenchIsEmpty, collections
StdLib.BenchVarType VarType(V) of a Variant holding a Double StdLib.BenchVarType StdLib.BenchVarType, allocated StdLib.BenchVarType, collections
StdLib.BenchTypeName TypeName(V) of the same StdLib.BenchTypeName StdLib.BenchTypeName, allocated StdLib.BenchTypeName, collections
StdLib.BenchAbs Abs(-I) StdLib.BenchAbs StdLib.BenchAbs, allocated StdLib.BenchAbs, collections
StdLib.BenchRound Round(D, 2) StdLib.BenchRound StdLib.BenchRound, allocated StdLib.BenchRound, collections
StdLib.BenchSqr Sqr(I) StdLib.BenchSqr StdLib.BenchSqr, allocated StdLib.BenchSqr, collections
StdLib.BenchInt Int(D) StdLib.BenchInt StdLib.BenchInt, allocated StdLib.BenchInt, collections
StdLib.BenchDateAdd DateAdd("d", 1, T) StdLib.BenchDateAdd StdLib.BenchDateAdd, allocated StdLib.BenchDateAdd, collections
StdLib.BenchYear Year(T) StdLib.BenchYear StdLib.BenchYear, allocated StdLib.BenchYear, collections
StdLib.BenchNow Now StdLib.BenchNow StdLib.BenchNow, allocated StdLib.BenchNow, collections
StdLib.BenchUBound UBound(A) of an array StdLib.BenchUBound StdLib.BenchUBound, allocated StdLib.BenchUBound, collections
Total - Standard library The section's cases together: the sum of RD-VBA's times over the sum of MS-VBA's Total - Standard library Total - Standard library, allocated Total - Standard library, collections

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 Excel.Block1000x10.Read
Block of 1,000 × 10, pass The loop over V(R, C), no call to Excel Excel.Block1000x10.Pass
Block of 1,000 × 10, write Range(...).Value = V Excel.Block1000x10.Write
Block of 1,000 × 10, total Read, pass and write Excel.Block1000x10.Total
Cell by cell, 1,000 × 10 10,000 cells, a get and a put each Excel.CellByCell1000x10.Total
Block of 100,000 × 10, read V = Range(...).Value Excel.Block100000x10.Read
Block of 100,000 × 10, pass The loop over V(R, C), no call to Excel Excel.Block100000x10.Pass
Block of 100,000 × 10, write Range(...).Value = V Excel.Block100000x10.Write
Block of 100,000 × 10, total Read, pass and write Excel.Block100000x10.Total
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 Total - Excel automation

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 bench sets 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 the badges branch) names that machine's processor.
  • Warm-up. Before its timed runs, rdc bench runs each case untimed until .NET has finished optimizing the code it calls, and rdc bench-msvba runs 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 bench collects 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 bench also gives what its fastest run allocated and the garbage collections of each generation made while it ran (the allocated and gc 0/1/2 columns). 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 bench gives 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 Long or Double loop runs faster than in MS-VBA. The same loop over Variant values, or over an array held in a Variant, is slower.
  • See what runs compiled. rdc compilation lists 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 bench times each Public 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