a$ = PEEK$(VARPTR(ByteArray(0)), lengthofarray&)
------------------
Lance
PowerBASIC Support
mailto:[email protected][email protected]</A>
------------------
Lance
PowerBASIC Support
mailto:[email protected][email protected]</A>
' Processor = 266 MHz ' MainStr = 80KB text file. ' wrd() = array of 3000 different phrases, ranging from 2 - 37 bytes long ' NumRecs = UBOUND(wrd) ' ' Average results from multiple scans on file ' result INSTR, 603 hits/scan in 6.39 sec. ' result myINSTR, 603 hits/scan in 6.25 sec. ' result ScanString, 603 hits/scan in 5.58 sec. ' test code as follows: (here for ScanString, but same kind was used for all) ' ------------------------------------------------------------------------------------ LOCAL c AS LONG, mPtr AS LONG, sPtr AS LONG, mLen AS LONG, sLen AS LONG, _ hit AS LONG, lRes AS LONG, tc1 AS LONG, tc2 AS LONG tc1 = GetTickCount() mPtr = STRPTR(MainStr) mLen = LEN(MainStr) FOR c = 0 TO Numrecs SearchStr = wrd(c) sPtr = STRPTR(SearchStr) sLen = LEN(SearchStr) lRes = ScanString(0, mPtr, mLen, sPtr, sLen) IF lRes > -1 THEN INCR hit DO lRes = ScanString(lRes + sLen, mPtr, mLen, sPtr, sLen) IF lRes > -1 THEN INCR hit LOOP WHILE lRes > -1 END IF NEXT tc2 = GetTickCount() - tc1 MSGBOX STR$(hit) + " " + FORMAT$(tc2/1000, "0.0000") + " Pos: " + FORMAT$(lRes), %MB_OK OR %MB_ICONINFORMATION, "ScanString" ' ------------------------------------------------------------------------------------
LOCAL tC AS LONG, enumI AS LONG LOCAL retVal AS LONG, MainStr AS STRING, SearchStr AS STRING SearchStr = ayFileDef(enumI, 2) retVal = ScanString( 0, STRPTR(MainStr), LEN(MainStr), STRPTR(SearchStr), LEN(SearchStr) ) 'retVal = INSTR( 1, MainStr, SearchStr )
Open "win32api.inc" for Binary as #1 Get$ #1,lof(1),a$ Close #1 b$ = "' ** VERSION.DLL Declares" ' << almost at the end LOCAL cnt as LONG cnt = 0 tc& = GetTickCount ap& = StrPtr(a$) aln& = len(a$) bpt& = StrPtr(b$) bln& = len(b$) Do rv& = ScanString(0,ap&,aln&,bpt&,bln&) ! inc cnt loop while cnt < 100 tc2& = GetTickCount - tc& MessageBox hWin,ByCopy str$(rv&),ByCopy str$(tc2&), _ %MB_OK or %MB_ICONINFORMATION
LOCAL fl as LONG redim patterns$(25) Open "win32api.inc" for Binary as #1 fl = lof(1) Get$ #1,fl,a$ Close #1 patterns$(0) = "VerQueryValue" patterns$(1) = "GetFileVersionInfo" patterns$(2) = "GetFileVersionInfoSize" patterns$(3) = "VerInstallFile" patterns$(4) = "VerFindFile" patterns$(5) = "SystemTimeToVariantTime" patterns$(6) = "VariantTimeToSystemTime" patterns$(7) = "VarDateFromStr" patterns$(8) = "WinExecError" patterns$(9) = "SHFreeNameMappings" patterns$(10) = "DragFinish" patterns$(11) = "DragAcceptFiles" patterns$(12) = "Shell_NotifyIcon" patterns$(13) = "ShellExecute" patterns$(14) = "ShellAbout" patterns$(15) = "SHFormatDrive" patterns$(16) = "SHGetNewLinkInfo" patterns$(17) = "SHGetFileInfo" patterns$(18) = "SHFileOperation" patterns$(19) = "SHAppBarMessage" patterns$(20) = "FindExecutable" patterns$(21) = "FindEnvironmentString" patterns$(22) = "ExtractIconEx" patterns$(23) = "ExtractIcon" patterns$(24) = "ExtractAssociatedIcon" aln& = len(a$) LOCAL cnt as LONG cnt = 0 tc& = GetTickCount Do rv& = ScanString(0,StrPtr(a$),aln&, _ StrPtr(patterns$(cnt)),len(patterns$(cnt))) ' -------------------------------------- SetWindowText hWnd,ByCopy str$(rv&) ' -------------------------------------- ! inc cnt Loop while cnt < 25 tc2& = GettickCount - tc& MessageBox hWin,ByCopy str$(rv&),ByCopy str$(tc2&), _ %MB_OK or %MB_ICONINFORMATION
#COMPILE EXE #INCLUDE "WIN32API.INC" '########################################################################## FUNCTION ScanString(BYVAL startpos AS LONG, _ BYVAL source AS LONG, BYVAL lnsrc AS LONG, _ BYVAL pattern AS LONG, BYVAL lnpatn AS LONG) AS LONG #REGISTER NONE ! mov edi, pattern ! mov al, [edi] ; get 1st byte ! mov esi, source ! mov ecx, lnsrc ! add esi, ecx ! neg ecx ! add ecx, startpos ! dec lnpatn ! jmp main_loop ' %%%%%%%%%%%%%%%%%%%%%%%%%%%% pre_loop: ! pop ecx ! inc ecx main_loop: ' ------------ ' unroll by 2 ' ------------ ! cmp al, [esi+ecx] ! je pre_sub ! inc ecx ! jz nMatch ! cmp al, [esi+ecx] ! je pre_sub ! inc ecx ! jnz main_loop ' ------------ ! jmp nMatch pre_sub: ! push ecx ! mov edi, pattern ! mov ebx, lnpatn sub_loop: ! mov ah, [esi+ecx+1] ! cmp ah, [edi+1] ! jne pre_loop ! inc ecx ! inc edi ! dec ebx ! jnz sub_loop ' %%%%%%%%%%%%%%%%%%%%%%%%%%%% ! pop eax ! add eax, lnsrc ! jmp Outa_Here nMatch: ! mov eax, -1 Outa_Here: ! mov FUNCTION, eax END FUNCTION ' ######################################################################## FUNCTION PBMAIN LOCAL fl AS LONG REDIM patterns$(25) OPEN "F:\PBDLL60\WINAPI\win32api.inc" FOR BINARY AS #1 ' OPEN "C:\WINNT5\SYSTEM32\SHELL32.DLL" FOR BINARY AS #1 fl = LOF(1) GET$ #1,fl,a$ CLOSE #1 patterns$(0) = "VerQueryValue" patterns$(1) = "GetFileVersionInfo" patterns$(2) = "GetFileVersionInfoSize" patterns$(3) = "VerInstallFile" patterns$(4) = "VerFindFile" patterns$(5) = "SystemTimeToVariantTime" patterns$(6) = "VariantTimeToSystemTime" patterns$(7) = "VarDateFromStr" patterns$(8) = "WinExecError" patterns$(9) = "SHFreeNameMappings" patterns$(10) = "DragFinish" patterns$(11) = "DragAcceptFiles" patterns$(12) = "Shell_NotifyIcon" patterns$(13) = "ShellExecute" patterns$(14) = "ShellAbout" patterns$(15) = "SHFormatDrive" patterns$(16) = "SHGetNewLinkInfo" patterns$(17) = "SHGetFileInfo" patterns$(18) = "SHFileOperation" patterns$(19) = "SHAppBarMessage" patterns$(20) = "FindExecutable" patterns$(21) = "FindEnvironmentString" patterns$(22) = "ExtractIconEx" patterns$(23) = "ExtractIcon" patterns$(24) = "ExtractAssociatedIcon" aln& = LEN(a$) LOCAL cnt AS LONG cnt = 0 b$ = "" tc2& = GetTickCount DO rv& = ScanString(0,STRPTR(a$),aln&, _ STRPTR(patterns$(cnt)),LEN(patterns$(cnt))) b$ = b$ + STR$(rv&) ! inc cnt LOOP WHILE cnt < 25 tc2& = GettickCount - tc2& cnt = 0 b$ = b$ + $CRLF tc& = GetTickCount DO rv& = INSTR(a$, patterns$(cnt)) b$ = b$ + STR$(rv&) ! inc cnt LOOP WHILE cnt < 25 tc& = GetTickCount - tc& b$ = B$ + $CRLF + "INSTR/MB = " + STR$(tc&/tc2&) MessageBox hWin&,BYVAL STRPTR(B$),"MB=" + STR$(tc2&) + " INSTR=" + STR$(tc&), _ %MB_OK OR %MB_ICONINFORMATION END FUNCTION
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Comment