Bancs d'essai : calcul numérique
This document is available in English
De l'arithmétique dans une boucle de 1 000 000 de tours (Iterations), sur des opérandes typés et Variant.
La source est le module Numeric.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 = 1000000
Cas
BenchLongCounterDoubleSum
S = S + I, un compteur Long et une somme Double.
' For I = 1 To 1000000: S = S + I: Next, with a Long counter and a Double sum (a Long sum overflows past I = 65536).
Public Sub BenchLongCounterDoubleSum()
Dim I As Long
Dim S As Double
For I = 1 To Iterations
S = S + I
Next
End Sub
BenchDoubleSum
La même boucle sur des Double.
Public Sub BenchDoubleSum()
Dim I As Double
Dim S As Double
For I = 1 To Iterations
S = S + I
Next
End Sub
BenchLongArithmetic
De l'arithmétique sur des Long, gardée dans les bornes par Mod.
' Long arithmetic only: the sum is kept in range by Mod.
Public Sub BenchLongArithmetic()
Dim I As Long
Dim S As Long
For I = 1 To Iterations
S = (S + I) Mod 1000003
Next
End Sub
BenchVariantSum
La même boucle, chaque opérande un Variant.
' the same loop with every operand a Variant: the effective type of each operation is decided from the values. The sum starts as a Double, so that
' each addition is of a Double and a Long.
Public Sub BenchVariantSum()
Dim I As Variant
Dim S As Variant
S = 0#
For I = 1 To Iterations
S = S + I
Next
End Sub
BenchCurrencyAndDate
Une somme Currency et une Date avancée d'un millième de jour à chaque tour.
' fixed-point and date arithmetic: a Currency sum of a Long counter, and a Date a thousandth of a day further each time.
Public Sub BenchCurrencyAndDate()
Dim I As Long
Dim C As Currency
Dim D As Date
D = #1/1/2000#
For I = 1 To Iterations
C = C + I
D = D + 0.001
Next
End Sub
BenchVariantTypedMix
Un Long et un Double ajoutés à une somme Variant.
' typed and Variant operands in one expression: a Long and a Double into a Variant sum, which decides its effective type from the values each time.
Public Sub BenchVariantTypedMix()
Dim I As Long
Dim D As Double
Dim V As Variant
V = 0
D = 0.5
For I = 1 To Iterations
V = V + I * D
Next
End Sub
Voir aussi
ACCUEIL • HOME | ℹ️ BIENVENUE • WELCOME | 🧩 BÂTISSONS • BUILD | RD-VBAL | SDK | 🌐 rubberduckvba.ca