|
|
|
This article will demonstrate that how CopyMemory can boost the performance of for some simple operations (e.g string append.). Here we will banchmark VB Mid function vs CopyMemory Api. |
Click here to copy the following block | Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long) Private Declare Function GetTickCount Lib "kernel32" () As Long Private Sub Form_Load() Dim sSave As String, Cnt As Long, T As Long, Pos As Long, Length As Long Const mStr = "Hello " Length = Len(mStr) sSave = Space(15000 * Length) T = GetTickCount Pos = 1 sSave = Space(15000 * Length) For Cnt = 1 To 15000 Mid(sSave, Pos, Length) = mStr Pos = Pos + Length Next Cnt MsgBox "It took Visual basic" + Str$(GetTickCount - T) + " msecs. to add 15000 times a string to itself." T = GetTickCount Pos = 0 sSave = Space(15000 * Length) For Cnt = 1 To 15000 CopyMemory ByVal StrPtr(sSave) + Pos, ByVal StrPtr(mStr), LenB(mStr) Pos = Pos + LenB(mStr) Next Cnt MsgBox "It took CopyMemory" + Str$(GetTickCount - T) + " msecs. to add 15000 times a string to itself." End Sub |
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|