Re: Why I need to use C for screen graphics

new topic     » goto parent     » topic index » view thread      » older message » newer message

Larry Miller wrote:
> 
> There are indeed cases where Euphoria is simply too slow. But this is not one
> of them. The performance bottleneck here is the Win32Lib function drawLine().
> This function is convenient to use but it is not fast. It calls getDC(),
> createPen(),
> and releaseDC() for every line drawn. I modified the RUNE_onClick() procedure
> as follows:
> 
> }}}
<eucode>
> procedure RUNE_onClick (integer self, integer event, sequence params)--params
> is ()
> -- run Euphoria drawing
> 
> integer x,y,PS_SOLID
> atom t0,hDC,hPen,void,hOldPen
> integer MsgBox
> t0 = time()
> PS_SOLID=0
> 
> setWindowBackColor( DRAWIN, backcolor )
> 
> set_rand(1500)
> hDC=getDC(DRAWIN)
> hPen=w32Func(xCreatePen,{PS_SOLID,1,0})
> hOldPen=w32Func(xSelectObject,{hDC,hPen})
> for i=1 to 100000 do
> 	x = rand(500)
> 	y = rand(500)
> 	void=w32Func(xMoveToEx,{hDC,x,y,NULL})
> 	void=w32Func(xLineTo,{hDC,x,y+2})
> end for
> void=w32Func(xSelectObject,{hDC,hOldPen})
> void=w32Func(xDeleteObject,{hPen})
> releaseDC(DRAWIN)
> 
> MsgBox = message_box(sprintf("Took %f time",{time()-t0}),"Test Euphoria", #0)
> 
> end procedure
> setHandler( RUNE, w32HClick, routine_id("RUNE_onClick"))
> 
> </eucode>
{{{

> 
> The speed improvement was dramatic. The original code executed in about 12
> seconds
> on my machine. The modified version took only .75 seconds.
> 
> Larry Miller

Thank you Larry. I did not know that the Windows functions were exposed in this
way with x in front of their names. I corrected your code - releaseDC should be
for DRAWIN.

I ran 3 options: My version with drawLine, my C version, and the Euphoria
version most similar to the C. My best times were 9.97, 0.51, 0.80 respectively.
So, Euphoria is still 60% slower. I now need to decide whether I should go for
maximum speed or the ease of programming in sticking to one language. I think for
now I will stick with Euphoria, and at some later date I will see where I can
increase speed.

By the way, after running the C version, the 1st Euphoria version speeds up to
3.95 seconds [in the same program run]. I have no idea why, but maybe someone can
use that information for understanding MS Windows or improving the Win32Lib.
There is no such speed up of the second Euphoria version.

I am going to attempt to use the Windows 2000/XP DC_PEN which lets you set the
color without having to create a new Pen object.

Andy Katz
B.S. Computer Science, 1978
Rensselaer Polytechnic Institute (RPI)

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu