Just a quick test
James
#include once "crt/time.bi"
#include once "Afx/AfxStr.inc"
'==============================================================================
Private Function FbParse OVERLOAD (sMainString As String,Byval nPosition As Long,sDlim As String = ",") As String
Dim As Long i,j,count
Dim As String s
If Len(sMainString) = 0 Then
Return ""
EndIf
count = 0
i = 1
Do
j = i
i = Instr(i,sMainString,sDlim)
If i > 0 Then
count += 1
i += 1
EndIf
Loop Until (i = 0) Or (count = nPosition)
If (i > 0) Or (count = nPosition - 1) Then
If i = 0 Then
s = Mid(sMainString,j)
Else
s = Mid(sMainString,j,i -1 -j)
EndIf
EndIf
Return s
End Function
'==============================================================================
Dim As String fbs = "one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,thirteen,fourteen,fifteen,sixteen,seventeen,eightteen,nineteen,twenty"
Dim As String fbs1
Dim As CBStr cbs = "one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,thirteen,fourteen,fifteen,sixteen,seventeen,eightteen,nineteen,twenty"
Dim As CBstr cbs1
Dim As CWStr cws = "one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,thirteen,fourteen,fifteen,sixteen,seventeen,eightteen,nineteen,twenty"
Dim As CWstr cws1
Dim As Long i,j
Dim As double z1,z2
'------------------------------------------------------------------------------
z1 = clock()
For j = 1 To 10000
For i = 1 To 20
'fbs1 = FF_Parse(fbs,i)
fbs1 = FbParse(fbs,i)
Next
Next
z2 = clock()
? "execution time For native String: " & z2-z1 & "ms" : ?
'------------------------------------------------------------------------------
z1 = clock()
For j = 1 To 10000
For i = 1 To 20
cbs1 = AfxStrParse(cbs,i)
Next
Next
z2 = clock()
? "execution time CBStr: " & z2-z1 & "ms" : ?
'------------------------------------------------------------------------------
z1 = clock()
For j = 1 To 10000
For i = 1 To 20
cws1 = AfxStrParse(cws,i)
Next
Next
z2 = clock()
? "execution time CWStr: " & z2-z1 & "ms" : ?
'------------------------------------------------------------------------------
z1 = clock()
For j = 1 To 10000
For i = 1 To 20
fbs1 = AfxStrParse(fbs,i)
Next
Next
z2 = clock()
? "execution time For native String using Afx: " & z2-z1 & "ms" : ?
sleep
Output:
execution time For native String: 78ms
execution time CBStr: 265ms
execution time CWStr: 266ms
execution time For native String using Afx: 312ms
One improvement that I will do will be to overload the += and &= operators to call the Add function. This will allow to use cws &= <some text> instead of cws.Add <some text>. For CBSTR I will add a fast appending function.