I made two other optimizations to Dave Roberts' code here: http://www.powerbasic.com/support/pb...388#post280388, and lately I've been using Dave's timer a lot too
(hey, I added one or two lines of code in there, just pull out a magnifying glass and you'll find them)

Code:
#COMPILE EXE #DIM ALL DECLARE FUNCTION QueryPerformanceCounter LIB "KERNEL32.DLL" ALIAS "QueryPerformanceCounter" (lpPerformanceCount AS QUAD) AS LONG DECLARE FUNCTION QueryPerformanceFrequency LIB "KERNEL32.DLL" ALIAS "QueryPerformanceFrequency" (lpFrequency AS QUAD) AS LONG '~~~~~~~~~~~A Variation of Dave Roberts' MACRO Timer~~~~~~~~~~~~~~~~~~~~~~~ MACRO onTimer LOCAL qFreq, qOverhead, qStart, qStop AS QUAD LOCAL f AS STRING f = "#.###" QueryPerformanceFrequency qFreq QueryPerformanceCounter qStart ' Intel suggestion. First use may be suspect QueryPerformanceCounter qStart ' So, wack it twice <smile> QueryPerformanceCounter qStop qOverhead = qStop - qStart ' Relatively small END MACRO MACRO goTimer = QueryPerformanceCounter qStart MACRO stopTimer = QueryPerformanceCounter qStop MACRO showTimer = USING$(f,(qStop - qStart - qOverhead)*1000000/qFreq /1000) + " milliseconds" '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ FUNCTION PBMAIN () AS LONG DIM hashByte() AS BYTE DIM hashByteHex () AS STRING * 2 DIM hashByteHexW () AS WORD 'use fast intrinsic WORD type rather than STRING * 2 DIM hexArr(255) AS WORD LOCAL hashText AS STRING LOCAL hashSize, i AS LONG hashSize = 3200000 ' bytes for example FOR i = 0 TO 255 'pre-calculate the hex translation array to avoid the HEX$() conversion later hexArr(i) = CVWRD(HEX$(i, 2)) NEXT REDIM hashByte(hashSize -1) AS BYTE FOR i = 0 TO hashSize- 1 hashByte(i) = RND(0,255) ' Output from a hashing algorithm, for example NEXT hashText = SPACE$(2*hashSize) REDIM hashByteHex( hashSize - 1) AS STRING * 2 AT STRPTR(hashText) REDIM hashByteHexW( hashSize - 1) AS WORD AT STRPTR(hashText) onTimer goTimer FOR i = 0 TO hashSize-1 hashByteHex(i) = HEX$( hashByte( i ),2 ) 'comment each line out in turn to compare speed ' hashByteHexW(i) = hexArr( hashByte( i ) ) 'comment each line out in turn to compare speed NEXT stopTimer MSGBOX showTimer & $CRLF & $CRLF & RIGHT$(hashText, 2000) END FUNCTION
Comment