Benchmarks: variables and parameters

Ce document est disponible en français


Where a procedure keeps its values: its parameters and locals, a variable of its module, a Static local, and Currency and Boolean values. Each loop runs 100,000 times (Iterations).

The source is the module Slots.bas of the corpus built into rdc. Each badge gives RD-VBA's time as a multiple of MS-VBA's (how the figures are measured).

Declarations

The module declares:

Private Const Iterations As Long = 100000

Private Total As Long

Cases

BenchWideActivations

A call with six typed parameters and four locals.

Slots.BenchWideActivations

' six typed parameters and four locals, for each of which an activation reserves storage.
Private Function Mix(ByVal A As Long, ByVal B As Long, ByVal C As Double, ByVal D As Integer, ByVal E As Boolean, ByVal F As Currency) As Long
    Dim W As Long
    Dim X As Double
    Dim Y As Integer
    Dim Z As Currency
    W = A + B
    X = C
    Y = D
    Z = F
    Mix = W
End Function

Public Sub BenchWideActivations()
    Dim I As Long
    Dim S As Long
    For I = 1 To Iterations
        S = Mix(I, 1, 2.5, 3, True, 4)
    Next
End Sub

BenchModuleVariableLoop

A module variable, read and written each time round.

Slots.BenchModuleVariableLoop

' a variable of the module, read and written each time round.
Public Sub BenchModuleVariableLoop()
    Dim I As Long
    Total = 0
    For I = 1 To Iterations
        Total = Total + 1
    Next
End Sub

BenchLocalVariableLoop

The same loop over a local variable.

Slots.BenchLocalVariableLoop

' the loop of BenchModuleVariableLoop over a local: what a module variable is measured against.
Public Sub BenchLocalVariableLoop()
    Dim I As Long
    Dim Local As Long
    For I = 1 To Iterations
        Local = Local + 1
    Next
End Sub

BenchStaticVariableLoop

The same loop over a Static local.

Slots.BenchStaticVariableLoop

' the same loop over a Static local, which lives as long as the module does.
Public Sub BenchStaticVariableLoop()
    Dim I As Long
    Static Kept As Long
    Kept = 0
    For I = 1 To Iterations
        Kept = Kept + 1
    Next
End Sub

BenchCurrencySum

A Currency sum.

Slots.BenchCurrencySum

' a Currency sum, whose payload is a scaled integer.
Public Sub BenchCurrencySum()
    Dim I As Long
    Dim S As Currency
    For I = 1 To Iterations
        S = S + 1.25@
    Next
End Sub

BenchBooleanFlag

A Boolean flag flipped and tested each time round.

Slots.BenchBooleanFlag

' a Boolean flag flipped and tested each time round.
Public Sub BenchBooleanFlag()
    Dim I As Long
    Dim B As Boolean
    Dim N As Long
    For I = 1 To Iterations
        B = Not B
        If B Then N = N + 1
    Next
End Sub

See also


ACCUEIL • HOME | ℹ️ BIENVENUE • WELCOME | 🧩 BÂTISSONS • BUILD | RD-VBAL | SDK | 🌐 rubberduckvba.ca