Forum
interesting performance differences with sub/endsub - Printable Version

+- Forum (https://www.boriel.com/forum)
+-- Forum: Compilers and Computer Languages (https://www.boriel.com/forum/forumdisplay.php?fid=12)
+--- Forum: ZX Basic Compiler (https://www.boriel.com/forum/forumdisplay.php?fid=11)
+---- Forum: Help & Support (https://www.boriel.com/forum/forumdisplay.php?fid=16)
+---- Thread: interesting performance differences with sub/endsub (/showthread.php?tid=383)



interesting performance differences with sub/endsub - nitrofurano - 10-08-2011

i were trying to make some experiences with display memory byte sequence references from coco2 (pmode 4) and msx1 (screen 2)
first i tried these:

coco2-pmode4 with sub/endsub (around 49 seconds):
Code:
dim a1, a2, v1, i as integer
sub vpokeln(a1,v1)
  let a2=16384 +  ((a1 band 31) bor ((a1 band 224)*8) bor ((a1 band 1792)/8) bor (a1 band 6144))
  if a1>=0 and a1<=6143 then: poke a2,v1:end if
  end sub
out 254,6
for i=400 to 6000
  vpokeln(i,40)
  next i
pause 0

msx1-screen2 with sub/endsub (around 60 seconds):
Code:
dim a1, a2, v1, i as integer
sub vpokech(a1,v1)
  let a2=16384+(((a1 band 7)*256) bor ((a1 band 248)/8) bor ((a1 band 1792)/8) bor (a1 band 6144))
  if a1>=0 and a1<=6143 then: poke a2,v1:end if
  end sub
out 254,6
for i=400 to 6000
  vpokech(i,40)
  next i
pause 0

but when i don't use sub/endsub, i got these results as benchmark:

coco2-pmode4 without sub/endsub (around 3 seconds):
Code:
dim i as integer
out 254,6
for i=400 to 6000
  poke 16384+((i band 31) bor ((i band 224)*8) bor ((i band 1792)/8) bor (i band 6144)),40
  next i
pause 0

msx1-screen2 with sub/endsub (around 7 seconds):
Code:
dim i as integer
out 254,6
for i=400 to 6000
  poke 16384+(((i band 7)*256) bor ((i band 248)/8) bor ((i band 1792)/8) bor (i band 6144)),40
  next i
pause 0

and i used the original zx-spectrum byte sequence display, i got this:

with sub/endsub (around 30 seconds):
Code:
dim a1, a2, v1, i as integer
sub vpokezx(a1,v1)
  let a2=16384+a1
  if a1>=0 and a1<=6143 then: poke a2,v1:end if
  end sub
out 254,6
for i=400 to 6000
  vpokezx(i,40)
  next i
pause 0

without sub/endsub (around 0.25 seconds or less):
Code:
dim i as integer
out 254,6
for i=400 to 6000
  poke 16384+i,40
  next i
pause 0

the question: what is causing so large performances differences from my expectations (i expected faster on the slower ones), and should i do for optimizing this?