matherp Guru
 Joined: 11/12/2012 Location: United KingdomPosts: 11472 |
| Posted: 05:02pm 14 Apr 2025 |
|
|
|
Eureka !!!
The issue is to do with how long it takes to allocate temporary memory to parse the commands.
This is fastest if the program finds free memory right at the top of the heap and doesn't need to search down it.
By fluke, the OPEN command allocates 512 bytes of memory which it then frees leaving a hole at the top of memory. We can simulate this by allocating 512 bytes of memory which we then free before entering the tight loop. See the attached. Now I need to discuss with Geoff, Tom and Gerry to see if we can do this in some sort of systemic way to improve performance of MMbasic
' Bubble Universe
'2 Nested loops each 52 =2704 points calculated VGA 'Pico 2040Anal @ 378MHz normal 316mS Framebuff 397mS 'Pico 2350Anal @ 378MHz normal 185mS Framebuff 185mS
'2 Nested loops each 66 =4356 points calculated VGA 'Pico 2040Anal @ 378MHz normal 553mS Framebuff 683mS 'Pico 2040Anal @ 378MHz Framebuff/CLS 607ms 'Pico 2350Anal @ 378MHz normal 341mS Framebuff 341mS 'Pico 2350HDMI @ 372MHz normal 333mS Framebuf 333mS 'Pico 2350HDMI @ 372MHz normal 278mS Framebuf 279mS CLS,remove arrays MODE 2 Font 8 Option fast trig on Dim SSS$,qqq$ 'allocate some memory at the top of the heap FRAMEBUFFER create FRAMEBUFFER write f 'Play mp3 "B:/hmp3" 'Play wav "b:/16" Pause 1000 'Play pause
Dim Float u(65),w(65),p,q,t,v=0,x=0,b Dim Integer c(65),d(65),n(65),m(32,65),nn,dd,xc,yc,xs,ys Dim Integer a,g,i,j,cc',y,z,f(16,65),l(16,65) 'Dim Integer e(65):Math Set 2,e() Const r=(2*Pi)/235,k=255,s=50 CLS RGB(black) t=Rnd*10 't=1 nn=Peek(varaddr n()) dd=Peek(varaddr d()) cc=Peek(varaddr c()) 'calculate centre and scale factor xc=MM.HRES\2:yc=MM.VRES\2 xs=MM.HRES/4.2:ys=MM.VRES/4.0 'Oval 'xs=MM.HRes/6:ys=MM.VRes/4 'Circular Erase sss$,qqq$ 'free the memory to create space for command parsing For a=0 To 65 For g=0 To 65 If a<18 And g<18 Then n(g)=RGB(0,255,0) Else n(g)=RGB(a*3.93,g*3.93,128*(a+g<65)) EndIf Next 'g Memory pack nn, Peek(varaddr m(0,a)),66,32 'pack pixel colours Next 'a Do CLS Inc t,0.035:g=0:Print Timer:Timer =0 For i=60To 255Step 3 'z=Peek(varaddr f(0,g)):Memory unpack z,cc,66,16 'y=Peek(varaddr l(0,g)):Memory unpack y,dd,66,16 'Pixel c(),d(),0'Box c(),d(),e(),e(),0,,0 b=r*i+t For j=0To 65:u(j)=Sin(i+v)+Sin(x):v=Cos(i+v)+Cos(x):x=u(j)+b:w(j)=v:Next Math Scale u(),xs,c():Math Scale w(),ys,d():Math add c(),xc,c():Math Add d(),yc,d() Memory unpack Peek(varaddr m(0,g)),nn,66,32 'unpack pixel colours Pixel c(),d(),n()'Box c(),d(),e(),e(),0,,n() 'Memory pack cc,z,66,16:Memory pack dd,y,66,16 Inc g Next 'i FRAMEBUFFER copy f,n Loop |