投稿日 | : 2002/12/12(Thu) 21:26 |
投稿者 | : Lantern |
Eメール | : |
URL | : |
タイトル | : Re^3: 特定の文字の数 |
試してみました
'test1:1文字づつ比較
'test2:文字検索
test1 test2
1回目: 0.1605 0.0064375
2回目: 0.1595625 0.0133125
3回目: 0.16175 0.0076875
4回目: 0.173375 0.0015
5回目: 0.1605 0.0064375
test1については2通り試してみました(コメントと非コメント)
が同じくらいでした
Private Sub Command1_Click()
Dim i As Integer
Dim l As Long
Dim lLen As Long
Dim bCnt As Integer
Dim lPos As Long
Dim strTestString As String
Dim sCmp As String
Dim sTm As Single
strTestString$ = vbNullString
For i% = 0 To 9999
strTestString$ = strTestString$ & "abcdefghijklmnopqrstuvwxyz"
Next i%
'test1
sTm! = Timer!
' lLen& = Len(strTestString$)
bCnt% = 0
l& = 0&
Do
sCmp$ = Mid$(strTestString$, l& + 1&, 1&)
If sCmp$ = vbNullString Then
Exit Do
End If
If StrComp(sCmp$, "c", vbBinaryCompare) = 0 Then
bCnt% = bCnt% + 1
End If
l& = l& + 1&
Loop While True
' For l& = 1& To lLen& - 1&
' If StrComp(Mid$(strTestString$, l&, 1), "c", vbBinaryCompare) = 0 Then
' bCnt% = bCnt% + 1
' End If
' Next l&
Me.Label1.Caption = Timer! - sTm!
' MsgBox ("COUNT" & CStr(bCnt%))
'test2
sTm! = Timer!
lPos& = 0&
bCnt% = 0
Do
lPos& = InStr(lPos& + 1&, strTestString$, "c", vbBinaryCompare)
If lPos& > 0& Then
bCnt% = bCnt% + 1
End If
Loop Until lPos& <= 0&
Me.Label2.Caption = Timer! - sTm!
'MsgBox ("COUNT" & CStr(bCnt%))
End Sub