An example of Mandelbrot (and speed test) :
Try to comment all lines beginning with 'local' to see the difference
#!/usr/bin/egsl
------------------------------------------------------------
-- MandelBrot (nov 2012) - EGSL 1.5.3 (B.Carette)
------------------------------------------------------------
openwindow(400,300,0,"Mandelbrot (EGSL)")
backcolor(255,255,255)
clearscreen()
--setframetimer(1000)
-- constants
local width, height, minre, maxre, mini, maxi, refactor, imfactor
width, height = screenwidth(), screenheight()
minre, maxre = -2.0, 1
mini = -1.2
maxi = mini+(maxre-minre)*height/width
refactor = (maxre-minre)/(width-1)
imfactor = (maxi-mini)/(height-1)
-- variables
local st, et
local cim, cre, zre, zim, zre2, zim2
local t
--MAIN PROGRAM
st = timerticks()
for y = 0, height+16 do
cim = maxi-y*imfactor
for x = 0, width do
cre = minre+x*refactor
zre = cre
zim = cim
for i = 0, 50 do
zre2 = zre*zre
zim2 = zim*zim
if zre2 + zim2 > 4 then
color(255-(i+5), i*5, i)
dot(x,y)
break
end
zim = 2*zre*zim+cim
zre = zre2-zim2+cre
end
end
end
et = timerticks()
t = tostring(et-st).." ms"
color(255,255,255)
drawtext(1, 10, t)
sync()
inkey()
closewindow()
--[[--
*** COMPARISONS ***
Interpreted Basic-like scripting languages :
* EGSL : +ou- 3000 ms / 600 to 800 ms (with variables as 'local')
* SDLBasic : 3400 ms
* FBSL : +ou- 10000 ms (freestyle Basic on win32)
Compiled Basics :
* PureBasic : 1438 ms / 422 ms compiled (win32)
1109 ms / 78 ms compiled (win32), with 'SetGadgetState()' after 2nd 'Next'
* GFA-BAsic : 315 ms / 198 ms compiled (win32)
* FreeBASIC : 220 to 400 ms
Lua + FLTK :
* murgaLua : 1900 to 2500 ms / 450 to 600 ms (with variables as 'local')
--]]--