📄 form1.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "用CacheSize属性测试缓存记录集的性能"
ClientHeight = 3090
ClientLeft = 60
ClientTop = 450
ClientWidth = 5460
LinkTopic = "Form1"
ScaleHeight = 3090
ScaleWidth = 5460
StartUpPosition = 2 '屏幕中心
Begin VB.CommandButton Command1
Caption = "用CacheSize属性测试缓存记录集的性能"
Height = 615
Left = 1560
TabIndex = 0
Top = 960
Width = 2415
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Public Sub CacheSizeX()
Dim rstRoySched As ADODB.Recordset
Dim strCnn As String
Dim sngStart As Single
Dim sngEnd As Single
Dim sngNoCache As Single
Dim sngCache As Single
Dim intLoop As Integer
Dim strTemp As String
'设置连接字符串的内容,请根据环境进行修改
strCnn = "Provider=sqloledb;Data Source=mynetserver;Initial Catalog=pubs;User Id=sa;Password=12345678;"
Set rstRoySched = New ADODB.Recordset
'打开 RoySched 表,生成记录集
rstRoySched.Open "roysched", strCnn, , , adCmdTable
'枚举记录集对象两次并记录经历的时间
'取开始操作的时间
sngStart = Timer
For intLoop = 1 To 2
rstRoySched.MoveFirst
Do While Not rstRoySched.EOF
'执行一个简单的操作来测试性能
strTemp = rstRoySched!title_id
rstRoySched.MoveNext
Loop
Next intLoop
'取结束操作的时间
sngEnd = Timer
'计算没有设置CacheSize属性时消耗的时间
sngNoCache = sngEnd - sngStart
'以 50 个记录为一组缓存记录
rstRoySched.MoveFirst
rstRoySched.CacheSize = 50
'取开始操作的时间。
sngStart = Timer
'枚举记录集对象两次并记录经历的时间
For intLoop = 1 To 2
rstRoySched.MoveFirst
Do While Not rstRoySched.EOF
'执行一个简单操作,进行性能测试
strTemp = rstRoySched!title_id
rstRoySched.MoveNext
Loop
Next intLoop
'取结束操作的时间
sngEnd = Timer
'计算设置CacheSize属性时消耗的时间
sngCache = sngEnd - sngStart
'显示性能结果
MsgBox "缓存性能结果:" & vbCr & _
" 没有缓存时: " & Format(sngNoCache, _
"##0.000") & "秒钟" & vbCr & _
" 缓存CacheSize设置为50: " & Format(sngCache, _
"##0.000") & " 秒钟"
rstRoySched.Close
End Sub
Private Sub Command1_Click()
Call CacheSizeX
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -