Re: Why I need to use C for screen graphics

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

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:

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,Black})
hOldPen=w32Func(xSelectObject,{hDC,hPen})
for i=1 to 100000 do
	x = rand(500)
	y = rand(500)
	void=w32Func(xMoveToEx,{hDC,x,y,0})
	void=w32Func(xLineTo,{hDC,x,y+2})
end for
void=w32Func(xSelectObject,{hDC,hOldPen})
void=w32Func(xDeleteObject,{hPen})
releaseDC(RUNE)

MsgBox = message_box(sprintf("Took %f time",{time()-t0}),"Test Euphoria", #0)

end procedure
setHandler( RUNE, w32HClick, routine_id("RUNE_onClick"))


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

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

Search



Quick Links

User menu

Not signed in.

Misc Menu