without David Roberts, John Gleason and i think Paul Dixon may of had a hand in the timing code too, this program would not of ever been made.
it makes use of their timing routines to report speed times of code
thanks guys.
a program to test 2 pieces of code using multiple loops, multiple samples, and multiple runs
averaged times for each set of samples is displayed
removing of skewed results would have been better, but i took the easy way and only used averages.
this program is very helpful when code written is to be use many times and where deciding on the fastest code.
the demo below compares the FORMAT$ to basic string building to create a returned string from a date routine(function).
the results would show that using the FORMAT$ statement is much slower, so for a date routine that is usually called many times in a program, FORMAT$ would not be the code to use as opposed to simply building a string.
this program is helping me to find the fastest code in programs that may call a function or repeat a line of code over may times, like 1,000,000 times, which is not unusual, or code in a dll that is used often.
it makes use of their timing routines to report speed times of code
thanks guys.
a program to test 2 pieces of code using multiple loops, multiple samples, and multiple runs
averaged times for each set of samples is displayed
removing of skewed results would have been better, but i took the easy way and only used averages.
this program is very helpful when code written is to be use many times and where deciding on the fastest code.
the demo below compares the FORMAT$ to basic string building to create a returned string from a date routine(function).
the results would show that using the FORMAT$ statement is much slower, so for a date routine that is usually called many times in a program, FORMAT$ would not be the code to use as opposed to simply building a string.
this program is helping me to find the fastest code in programs that may call a function or repeat a line of code over may times, like 1,000,000 times, which is not unusual, or code in a dll that is used often.
Code:
'timermast.bas 'pbcc 4.04 ' #COMPILE EXE #DIM ALL #REGISTER NONE GLOBAL glloopsinasample AS LONG GLOBAL glsamples AS LONG GLOBAL glrunstomake AS LONG GLOBAL TOTALTIME AS SINGLE 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" '==================================================================================================== 'EDIT HERE 'HERE IS WHERE YOU BASICALLY SET UP YOUR VARIABLES AND CODE FUNCTION initiateloopsvalues() AS LONG glloopsinasample=100'0000 'no of loops in a sample glsamples=100 'no of samples in a test, the higher the better glrunstomake=3 'no of test to make, at least make it 2 for better results END FUNCTION FUNCTION testcode1(temp AS LONG) AS STRING LOCAL m,d,y AS LONG testcode1=FORMAT$(M,"00") + "/" + FORMAT$(D,"00") + "/" + FORMAT$(Y,"0000") END FUNCTION FUNCTION testcode2(temp AS LONG) AS STRING LOCAL m,d,y AS LONG testcode2=RIGHT$("0"+TRIM$(STR$(M)),2)+"/"+RIGHT$("0"+TRIM$(STR$(D)),2)+ "/" +RIGHT$("000"+TRIM$(STR$(Y)),4) END FUNCTION '==================================================================================================== FUNCTION PBMAIN () AS LONG REGISTER I AS LONG REGISTER J AS LONG LOCAL K AS LONG initiateloopsvalues onTimer K=0 STARTARUN: INCR K TOTALTIME=0.0 J=0& START1: INCR J gotimer FOR I=1& TO glloopsinasample '========================================================= 'call to the code tested first goes here 'EDIT HERE testcode1(0) '========================================================= NEXT I stoptimer TOTALTIME=TOTALTIME+(qStop - qStart - qOverhead)*1000000/qFreq/1000 SLEEP 0 IF J<glsamples THEN GOTO START1 STDOUT "-------------------------"; STDOUT "code #1 no of samples"+STR$(glsamples)+" run no"+STR$(K) STDOUT USING$(f,(TOTALTIME/glsamples)) + " milliseconds" TOTALTIME=0.0 J=0& START2: INCR J gotimer FOR I=1& TO glloopsinasample '========================================================= 'call to the code tested second goes here 'EDIT HERE testcode2(0) '========================================================= NEXT I stoptimer TOTALTIME=TOTALTIME+(qStop - qStart - qOverhead)*1000000/qFreq/1000 SLEEP 0 IF J<glsamples THEN GOTO START2 STDOUT "-------------------------"; STDOUT "code #2 no of samples"+STR$(glsamples)+" run no"+STR$(K) STDOUT USING$(f,(TOTALTIME/glsamples)) + " milliseconds" IF K<glrunstomake THEN GOTO STARTARUN WAITKEY$ END FUNCTION
Comment