好奇,于是便也做了个测试。
测试步骤:
1. Windows 2000 SP4 ,打开ACCESS 2003 SP3, 新建空z.mdb
2. 新建module,代码如下,运行createEnv() 建立测试表及记录
Option Compare Database
Option Explicit
Dim conn As ADODB.Connection
Public Sub createEnv()
Dim sSQL As String
Dim i As Integer
sSQL = "create table t( id integer constraint pk_t primary key, f1 integer)"
CurrentProject.Connection.Execute sSQL
For i = 1 To 10000
sSQL = "insert into t values(" & i & "," & i * 2 & ")"
CurrentProject.Connection.Execute sSQL
Next i
End Sub
Public Sub t1() 'test DLOOKUP
Dim sSQL As String
Dim i As Integer
Dim iResult As Integer
Debug.Print Now(), "DLOOKUP Started..."
For i = 1 To 10000
iResult = DLookup("f1", "t", "id=" & i)
Next i
Debug.Print Now(), "DLOOKUP Accomplished..."
End Sub
Public Sub t2() 'test MLOOKUP
Dim sSQL As String
Dim i As Integer
Dim iResult As Integer
Set conn = CurrentProject.Connection
Debug.Print Now(), "MLOOKUP Started..."
For i = 1 To 10000
iResult = mLookUp("f1", "t", "id=" & i)
Next i
Debug.Print Now(), "MLOOKUP Accomplished..."
End Sub
Public Function mLookUp(ByVal strFieldName As String, ByVal strTableName As String, Optional ByVal strWhere As String) As Variant
Dim sql As String
sql = "select " & strFieldName & " From " & strTableName
If Len(strWhere) > 0 Then sql = sql & " where " & strWhere
On Error Resume Next
mLookUp = conn.Execute(sql)(0)
If Err <> 0 Then
Err.Clear
mLookUp = Null
End If
End Function
3. 关闭系统中无关程序,打开taskmgr.exe, 交叉运行两个T1(), T2() 以防止先后顺序对测试的影响。 结果
3/17/2009 11:01:42 PM DLOOKUP Started...
3/17/2009 11:01:51 PM DLOOKUP Accomplished...
3/17/2009 11:02:01 PM MLOOKUP Started...
3/17/2009 11:02:18 PM MLOOKUP Accomplished...
3/17/2009 11:02:52 PM MLOOKUP Started...
3/17/2009 11:03:09 PM MLOOKUP Accomplished...
3/17/2009 11:03:13 PM DLOOKUP Started...
3/17/2009 11:03:23 PM DLOOKUP Accomplished...
3/17/2009 11:04:20 PM DLOOKUP Started...
3/17/2009 11:04:29 PM DLOOKUP Accomplished...
3/17/2009 11:04:34 PM MLOOKUP Started...
3/17/2009 11:04:52 PM MLOOKUP Accomplished...
**************
* 一切皆有可能 *
**************
ACMAIN - Access论坛回贴准则(个人)
QQ群 48866293 / 12035577 / 7440532 / 13666209
http://www.accessbbs.cn/bbs/index.php
http://www.accessoft.com/bbs/index.asp
http://www.office-cn.net/vvb/?fromuid=141646
http://www.access-programmers.co.uk/forums
http://www.office-cn.net/home/space.php?uid=141646