This was in response to a query by Tim Collins here.
Comments here.
Comments here.
Code:
#COMPILE EXE "Benchmark.exe" #DIM ALL 'designed for PBWIN 10.4 and J Roca includes 'by: Jim Fritts 'Stable benchmarking platform to compare the completion time for 2 different routines using 100 iterations for each process. 'Stability is +/- 0.001 seconds. 'All string assignments should be done outside the thread to promote stability. #INCLUDE "win32api.inc" GLOBAL gAction AS LONG GLOBAL g_Result AS LONG GLOBAL gsX AS STRING GLOBAL gsY AS STRING GLOBAL gsZ AS STRING GLOBAL XC AS LONG GLOBAL DONE AS DOUBLE GLOBAL TEST1 AS DOUBLE GLOBAL TEST2 AS DOUBLE GLOBAL START AS DOUBLE FUNCTION PBMAIN AS LONG gsX = STRING$(80, "X") 'create the test string gsY = STRING$(80, "Y") 'create the test string gsZ = STRING$(80, "Z") 'create the test string SLEEP 2 LOCAL hThread AS DWORD THREAD CREATE ProcessTest(1) TO hThread 'run real-time comparison thread THREAD CLOSE hThread TO hThread SLEEP 10 DO WHILE gAction = 1 SLEEP 10 LOOP END FUNCTION THREAD FUNCTION ProcessTest(BYVAL yyy AS LONG) AS LONG gAction = 1 g_Result = SetPriorityClass(GetCurrentProcess(), %REALTIME_PRIORITY_CLASS) 'Compare the times for processing each routine Start = TIMER FOR XC = 1 TO 100 GOSUB Process_1 SLEEP 1 NEXT Done = TIMER Test1 = Done - Start Start = TIMER FOR XC = 1 TO 100 GOSUB Process_2 SLEEP 1 NEXT Done = TIMER Test2 = Done - Start ? "Process Completed." + $CRLF + _ USING$("&##.####", "Seconds using three strings", Test1) + $CRLF + _ USING$("&##.####", "Seconds using concatenation", Test2) gAction = 0 g_Result = SetPriorityClass(GetCurrentProcess(), %NORMAL_PRIORITY_CLASS) EXIT FUNCTION Process_1: 'Put your code here 'PRINT gsX; gsY; gsZ RETURN Process_2: 'Put your code here 'PRINT BUILD$(gsX, gsY, gsZ) RETURN END FUNCTION
Comment