同じ API 呼び出しが、VB.NET よりも VB6 の方がはるかに速く返される理由を誰か説明できますか?
これが私のVB6コードです:
Public Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hWnd As Long) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Function GetWindowTextEx(ByVal uHwnd As Long) As String
Dim lLen&
lLen = GetWindowTextLength(uHwnd) + 1
Dim sTemp$
sTemp = Space(lLen)
lLen = GetWindowText(uHwnd, sTemp, lLen)
Dim sRes$
sRes = Left(sTemp, lLen)
GetWindowTextEx = sRes
End Function
そして、ここに私のVB.NETコードがあります:
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Integer, ByVal lpWindowText As String, ByVal cch As Integer) As Integer
Dim sText As String = Space(Int16.MaxValue)
GetWindowText(hwnd, sText, Int16.MaxValue)
各バージョンを 1000 回実行しました。
VB6 バージョンでは 2.04893359351538 ミリ秒が必要でした。VB.NET バージョンでは 372.1322491699365 ミリ秒が必要でした。
リリース バージョンとデバッグ バージョンはほぼ同じです。
ここで何が起きてるの?