Bancs d'essai : variables et paramètres
This document is available in English
Là où une procédure garde ses valeurs : ses paramètres et ses variables locales, une variable de son module, une variable locale Static, et des valeurs Currency et Boolean. Chaque boucle fait 100 000 tours (Iterations).
La source est le module Slots.bas du corpus intégré à rdc. Chaque badge donne le temps de RD-VBA en multiple de celui de MS-VBA (comment les chiffres sont mesurés).
Déclarations
Le module déclare :
Private Const Iterations As Long = 100000
Private Total As Long
Cas
BenchWideActivations
Un appel à six paramètres typés et quatre variables locales.
' 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
Une variable de module, lue et écrite à chaque tour.
' 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
La même boucle sur une variable locale.
' 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
La même boucle sur une variable locale Static.
' 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
Une somme Currency.
' 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
Un indicateur Boolean inversé et testé à chaque tour.
' 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
Voir aussi
ACCUEIL • HOME | ℹ️ BIENVENUE • WELCOME | 🧩 BÂTISSONS • BUILD | RD-VBAL | SDK | 🌐 rubberduckvba.ca