Benchmarks: statements

Ce document est disponible en français


The statements other than the Let assignment of a variable. Each case runs its statement 100,000 times.

The source is the module Statements.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 a user-defined type:

Private Type Pair
    X As Long
    Y As Long
End Type

Cases

BenchSetAssignment

Set D = C of an object variable. Counter is on the Calls page.

Statements.BenchSetAssignment

Public Sub BenchSetAssignment()
    Dim C As Counter
    Set C = New Counter
    Dim D As Counter
    Dim I As Long
    For I = 1 To 100000
        Set D = C
    Next
End Sub

BenchMemberAssignment

P.X = I, a property of an object. It assigns X of Point.

Statements.BenchMemberAssignment

Public Sub BenchMemberAssignment()
    Dim P As Point
    Set P = New Point
    Dim I As Long
    For I = 1 To 100000
        P.X = I
    Next
End Sub

BenchRecordFieldAssignment

R.X = I, a field of a user-defined type. Pair is in the declarations of the module.

Statements.BenchRecordFieldAssignment

Public Sub BenchRecordFieldAssignment()
    Dim R As Pair
    Dim I As Long
    For I = 1 To 100000
        R.X = I
    Next
End Sub

BenchSelectCase

Select Case I Mod 4 with three branches.

Statements.BenchSelectCase

Public Sub BenchSelectCase()
    Dim I As Long
    Dim S As Long
    For I = 1 To 100000
        Select Case I Mod 4
            Case 0
                S = S + 1
            Case 1, 2
                S = S + 2
            Case Else
                S = S + 3
        End Select
    Next
End Sub

BenchConditions

If, ElseIf and Do While conditions: comparisons joined with And.

Statements.BenchConditions

' the conditions of If and of a loop: comparisons, And-ed.
Public Sub BenchConditions()
    Dim I As Long
    Dim S As Long
    Do While I < 100000
        I = I + 1
        If I Mod 3 = 0 And I > 10 Then
            S = S + 1
        ElseIf I Mod 5 = 0 Then
            S = S - 1
        End If
    Loop
End Sub

BenchMidStatement

The Mid$ statement: Mid$(S, 1, 1) = "r".

Statements.BenchMidStatement

Public Sub BenchMidStatement()
    Dim S As String
    S = "RD-VBA"
    Dim I As Long
    For I = 1 To 100000
        Mid$(S, 1, 1) = "r"
    Next
End Sub

BenchOnErrorResumeNext

A loop under On Error Resume Next, dividing by zero one time in ten.

Statements.BenchOnErrorResumeNext

' a loop under On Error Resume Next, a division by zero one time in ten: what the error handler costs where it is in effect, and where it is used.
Public Sub BenchOnErrorResumeNext()
    On Error Resume Next
    Dim I As Long
    Dim D As Double
    For I = 1 To 100000
        D = 10 / (I Mod 10)
    Next
End Sub

Class modules

Point

A class with two public variables.

Option Explicit

Public X As Long
Public Y As Long

See also


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