Bancs d'essai : instructions

This document is available in English


Les instructions autres que l'affectation Let d'une variable. Chaque cas exécute son instruction 100 000 fois.

La source est le module Statements.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 un type défini par l'utilisateur :

Private Type Pair
    X As Long
    Y As Long
End Type

Cas

BenchSetAssignment

Set D = C d'une variable objet. Counter est à la page Appels.

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, une propriété d'un objet. Il affecte X de 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, un champ d'un type défini par l'utilisateur. Pair est dans les déclarations du 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 à trois 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

Les conditions de If, ElseIf et Do While : des comparaisons jointes par 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

L'instruction Mid$ : 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

Une boucle sous On Error Resume Next, qui divise par zéro une fois sur dix.

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

Modules de classe

Point

Une classe à deux variables publiques.

Option Explicit

Public X As Long
Public Y As Long

Voir aussi


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