The attached access file contains two tables, three queries, a module and a stopwatch class. If these elements are transferred to your own application, you will be able to carry out speed tests and speed comparisons for a large number of tasks without great effort. This solution is not as broad and graphically expanded as Colin Riddington's tests, but can be adapted very quickly for self-help.
The QueryPerformanceCounter is used for the measurements, which offers higher precision than methods that are derived from the system clock. This also makes it easier to evaluate individual executions of queries.
The simple code: The queries to be checked (alternatively sub-procedures for VBA tests) and a description are stored in an array. The sAddition variable can be used to document variants of measurements, e.g. changed indexing for the same queries. The cOne flag can be used to control whether a one-off measurement is carried out, because you hardly want to run anything in a loop for several minutes.
Here in the presentation, elements from Query runs slow with NOT IN were used for code and images of the results.
Single run to estimate the running time:
Repeated runs to refine the results:
Have fun applying.
The QueryPerformanceCounter is used for the measurements, which offers higher precision than methods that are derived from the system clock. This also makes it easier to evaluate individual executions of queries.
The simple code: The queries to be checked (alternatively sub-procedures for VBA tests) and a description are stored in an array. The sAddition variable can be used to document variants of measurements, e.g. changed indexing for the same queries. The cOne flag can be used to control whether a one-off measurement is carried out, because you hardly want to run anything in a loop for several minutes.
Code:
Sub start_Test()
Dim QSU As New QpcStoppuhr
Dim db As DAO.Database
Dim qd As DAO.QueryDef
Dim rs As DAO.Recordset
Dim rsE As DAO.Recordset
Dim S As Variant
Dim sAddition As String
Dim i As Long, j As Long
Const cRun As Long = 6
Const cOne As Boolean = True ' for True: one-time run to estimate the running time
' Pairs: QueryName, TestName
S = Array("qryTestG", "Indexed Order By", _
"qryTestH", "Where vs Having", _
"qryTestI", "Indexed Filter fields", _
"qryTestJ", "First vs GroupBy", _
"qryStacked2", "Stacked Queries", _
"qryTestL", "Subquery 1", _
"qryTestM", "Subquery 2")
Set db = CurrentDb
If cOne Then
Set rsE = db.OpenRecordset("SELECT Test, Addition, Duration FROM tblLog_One", dbOpenDynaset)
With rsE
sAddition = "singly"
For i = 0 To UBound(S) Step 2
Set qd = db.QueryDefs(S(i))
QSU.StartT
Set rs = qd.OpenRecordset(dbOpenSnapshot)
rs.MoveLast
QSU.StopT
.AddNew
.Fields("Test") = Format(i \ 2 + 1, "00_") & S(i + 1)
.Fields("Addition") = sAddition
.Fields("Duration") = QSU.TimeString
.Update
rs.Close
qd.Close
Next
.Close
End With
DoCmd.OpenTable "tblLog_One"
Else
Set rsE = db.OpenRecordset("SELECT Run, Test, Addition, Duration FROM tblLog", dbOpenDynaset)
With rsE
sAddition = "normal"
For j = 0 To cRun
For i = 0 To UBound(S) Step 2
Set qd = db.QueryDefs(S(i))
QSU.StartT
Set rs = qd.OpenRecordset(dbOpenSnapshot)
rs.MoveLast
QSU.StopT
If j > 0 Then ' skip the starting lap
.AddNew
.Fields("Run") = j
.Fields("Test") = Format(i \ 2 + 1, "00_") & S(i + 1)
.Fields("Addition") = sAddition
.Fields("Duration") = QSU.time
.Update
rs.Close
qd.Close
End If
Next
Next
.Close
End With
DoCmd.OpenQuery "qCTLog"
End If
MsgBox "Test completed"
End Sub
Single run to estimate the running time:
Repeated runs to refine the results:
Have fun applying.