After putting debug code into my application I realised that GRAPHIC BOX, which I was using to draw rectangles, was running not just slowly, but very slowly. I suspect that the cause is something in my PC's configuration, tiny amount of RAM, etc., but I did just wonder how fast it would run on "proper PCs", like yours!
Here's a little test routine which compiles with V5, and draws 1,000 boxes with GRAPHIC BOX, then 1,000 boxes with the API moveto/lineto functions. I'm getting timings of about 15secs and about 0secs, respectively. If your observations are much closer, then more iterations or a more accurate timebase would be a good plan.
Here's a little test routine which compiles with V5, and draws 1,000 boxes with GRAPHIC BOX, then 1,000 boxes with the API moveto/lineto functions. I'm getting timings of about 15secs and about 0secs, respectively. If your observations are much closer, then more iterations or a more accurate timebase would be a good plan.
Code:
' to compare speed of GRAPHIC BOX with that of API lineto ' Chris Holbrook Nov 2008 ' #COMPILE EXE #DIM ALL #INCLUDE ONCE "WIN32API.INC" %iterations = 1000 FUNCTION PBMAIN () AS LONG LOCAL x, y, i, start AS LONG LOCAL hGW, hdc AS DWORD LOCAL skey AS STRING DESKTOP GET CLIENT TO x, y GRAPHIC WINDOW "", 0, 0, x, y TO hGW GRAPHIC ATTACH hGW, 0 start = TIMER FOR i = 1 TO %iterations GRAPHIC BOX (100, 100) - (400, 400), 0, %BLACK, -2, 0 NEXT GRAPHIC SET POS (100, 500) GRAPHIC PRINT STR$(%iterations) + " iterations using GRAPHIC BOX: " + FORMAT$(TIMER - start, "#.00") + " seconds" start = TIMER GRAPHIC GET DC TO hdc FOR i = 1 TO %iterations moveto hdc, 500, 100 lineto hdc, 800, 100 lineto hdc, 800, 400 lineto hdc, 500, 400 lineto hdc, 500, 100 NEXT GRAPHIC SET POS (500, 500) GRAPHIC PRINT STR$(%iterations) + " iterations using lineto: " + FORMAT$(TIMER - start, "#.00") + " seconds" GRAPHIC WAITKEY$ TO skey GRAPHIC WINDOW END END FUNCTION
Comment