Benchmarks: numeric
Ce document est disponible en français
Arithmetic in a loop of 1,000,000 iterations (Iterations), over typed and Variant operands.
The source is the module Numeric.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 = 1000000
Cases
BenchLongCounterDoubleSum
S = S + I with a Long counter and a Double sum.
' 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
The same loop over Double values.
Public Sub BenchDoubleSum()
Dim I As Double
Dim S As Double
For I = 1 To Iterations
S = S + I
Next
End Sub
BenchLongArithmetic
Long arithmetic, kept in range with 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
The same loop with every operand a 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
A Currency sum and a Date advanced a thousandth of a day each time.
' 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
A Long and a Double added into a Variant sum.
' 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
See also
ACCUEIL • HOME | ℹ️ BIENVENUE • WELCOME | 🧩 BÂTISSONS • BUILD | RD-VBAL | SDK | 🌐 rubberduckvba.ca