Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
%IDC_REG = 500
%IDC_INSTR = 501
Global hDlg As Dword, iLoop, iLoopMax As Long
Global qFreq, qStart, qStop As Quad, DeltaTime As Single
Function PBMain() As Long
Dialog New Pixels, 0, "Speed Test",300,300,120,100, %WS_OverlappedWindow To hDlg
iLoopMax = 10000
Control Add Button, hDlg, %IDC_REG, "REG", 10,10,100,20
Control Add Button, hDlg, %IDC_INSTR, "INSTR", 10,40,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local w,h As Long
Select Case Cb.Msg
Case %WM_InitDialog
QueryPerformanceFrequency qFreq
Case %WM_Command
If Cb.Ctl = %IDC_Reg Then REGWAY
If Cb.Ctl = %IDC_Instr Then INSTRWAY
End Select
End Function
Sub REGWAY
QueryPerformanceCounter qStart
For iLoop = 1 To iLoopMax 'test loop
Local temp$, iLen,iPos As Long
iLen=0 : iPos=0
temp$ = "abc" + Chr$(10) + "def" + $CrLf + "ghi" + Chr$(10) + "jkl"
Do
iPos = iPos + iLen
RegExpr "\s[^\r]\n" In temp$ At iPos To iPos, iLen
If iPos Then temp$ = StrInsert$(temp$, Chr$(13), iPos+1) : Incr iPos
Loop While iPos
Clipboard Reset
Clipboard Set Text temp$
Next iLoop
QueryPerformanceCounter qStop
DeltaTime = (qStop-qStart)/qFreq
? "REG " + Format$(DeltaTime,"0.###") & " seconds"
End Sub
Sub INSTRWAY
QueryPerformanceCounter qStart
For iLoop = 1 To iLoopMax 'test loop
Local temp$, iLen,iPos As Long
temp$ = "abc" + Chr$(10) + "def" + $CrLf + "ghi" + Chr$(10) + "jkl"
iPos = 1
Do
iPos = InStr(iPos,temp$,Chr$(10))
If iPos Then
If Mid$(temp$,iPos-1,1)<>Chr$(13) Then temp$ = StrInsert$(temp$, Chr$(13), iPos) : Incr iPos
Incr iPos
End If
Loop While iPos
Clipboard Reset
Clipboard Set Text temp$
Next iLoop
QueryPerformanceCounter qStop
DeltaTime = (qStop-qStart)/qFreq
? "INSTR " + Format$(DeltaTime,"0.###") & " seconds"
End Sub
'gbs_01080
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm