Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > Fastest time printing binary in BASIC or Assembly
2024-01-11 08:49
Mr SQL

Registered: Feb 2023
Posts: 114
Fastest time printing binary in BASIC or Assembly

Interesting Video on 8-bit show and tell:
https://www.youtube.com/watch?v=P8t6otqoz_E

What's the fastest time you can print binary to the screen in BASIC or Assembly?

I got it down to 26 seconds in BASIC without a pre-calc routine.
 
... 29 posts hidden. Click here to view all posts....
 
2024-01-18 13:38
Krill

Registered: Apr 2002
Posts: 2845
Quoting spider-j
Do you mean one should generate tables elsewhere
As pointed out by CJam and others, there's a magical border of complexity when you really should generate the data externally. (And then just incbin that binary, of course, not generate a wall of asm .byte statements.)

And on the other complexity end, using loop macros etc. is just a lazy way to code, producing bloat, as that stuff (simple tables and unrolled code) can most often be generated at init-run-time, producing smaller output.

So, there are good reasons to use loop macros etc., but not that many.
2024-01-18 13:51
chatGPZ

Registered: Dec 2001
Posts: 11118
Quote:
And then just incbin that binary, of course, not generate a wall of asm .byte statements.

Cracks me up every single time i see people doing this... wth
2024-01-18 14:35
spider-j

Registered: Oct 2004
Posts: 445
Well, while these may all be good ideas in theory, I actually don't know how to "incbin" into CSDb forums for posting a quick and dirty code snippet ;-)
2024-01-18 14:58
Krill

Registered: Apr 2002
Posts: 2845
Quoting spider-j
Well, while these may all be good ideas in theory, I actually don't know how to "incbin" into CSDb forums for posting a quick and dirty code snippet ;-)
Nobody said anything like that.

And code-golf or general prototyping is a good reason for loop macros. =)
2024-01-18 21:39
spider-j

Registered: Oct 2004
Posts: 445
Quoting Krill
Nobody said anything like that.

And code-golf or general prototyping is a good reason for loop macros. =)

Okay, now I see. I got you completely wrong. I thought it was about the code I posted here.
2024-01-18 22:49
Mr SQL

Registered: Feb 2023
Posts: 114
Quoting ChristopherJam
Yes to generate tables elsewhere most of the time (though for a case as simple as this I'd probably inline a loop plus expression too), but if you mean "do you generate the table once then copy and paste a huge list of .byte statements into your source code" then definitely not!

Who says you can't?

I would be more interested to see examples for optimizing Robin's coding exercise with any semantics.
2024-01-18 22:56
Mr SQL

Registered: Feb 2023
Posts: 114
Quoting ChristopherJam
This one takes 13.18 seconds (as compared to just doing print:return in the printing routine, which takes 8.91 - the binary conversion+print is hence around 4.27). So yeah, ws is correct. It's dominated by screen scroll time.

Those times are if you run after loading from reset - if you start at bottom of the screen everything is slower, because yous start scrolling immediately.

0 gosub9:ti$="000000":goto2
1 printd$(i/16)d$(iand15):return
2 fori=0to255:gosub1:next
3 print"time:"ti/60:end
7 data"0000","0001","0010","0011","0100","0101","0110","0111"
8 data"1000","1001","1010","1011","1100","1101","1110","1111"
9 dimd$(16):fori=0to15:readd$(i):next:return


This is another excellent design. Adding the decimal form and spacing to match Robin's output will add slightly to the print time.
2024-01-19 03:34
aeeben

Registered: May 2002
Posts: 42
10 TI$="000000":E=15:DIMB$(E):SYS58692:FORA=.TOE:READB$(A):NEXT:D=1/A
20 FORA=.TO255:PRINTB$(A*D)B$(AANDE):NEXT:PRINTTI/60:DATA0000,0001,0010
30 DATA0011,0100,0101,0110,0111,1000,1001,1010,1011,1100,1101,1110,1111

-> 11.8166667 sec.

Multiply by 1/16 is a bit faster than division. Constants in variables is a bit faster. I didn't see any gains from using a subroutine.
2024-01-19 04:33
aeeben

Registered: May 2002
Posts: 42
For laughs, I wanted to try this on Bunny Basic too :D

1 TI$="000000":SYS49152,2:PRINTTI/60:END
2 CLR:PRINT"{CLR}";:C=48:B=49:G=128:H=64:I=32:J=16:K=8:L=4:M=2:N=1:F=256:O=65490
3 A=C:D=VANDG:IFD=GTHENA=B
4 SYSO:A=C:D=VANDH:IFD=HTHENA=B
5 SYSO:A=C:D=VANDI:IFD=ITHENA=B
6 SYSO:A=C:D=VANDJ:IFD=JTHENA=B
7 SYSO:A=C:D=VANDK:IFD=KTHENA=B
8 SYSO:A=C:D=VANDL:IFD=LTHENA=B
9 SYSO:A=C:D=VANDM:IFD=MTHENA=B
10 SYSO:A=C:D=VANDN:IFD=NTHENA=B
11 PRINTCHR$(A)
12 V=V+1:IFV<>FTHENGOTO3
13 END

- Bunny Basic interpreter (bunnybasic64.prg) is loaded at $c000
- Type RUN to start from line 1 in slow BASIC mode
- SYS49152,2 calls Bunny Basic program at line 2 and returns to slow BASIC at line 13 (END), to print out the value TI/60
- CLR clears all Bunny Basic variables
- SYSO / SYS65490 is CHROUT. Bunny Basic puts low 8 bits of variable A in Accumulator at SYS

-> 11.6 seconds, but this is all bitwise operations without the nybble lookup, and kernal screen scrolling is taking most of the time

Let's try with nybbles:
1 TI$="000000":SYS49152,2:PRINTTI/60:END
2 CLR:PRINT"{CLR}";:B=16:F=256:E=15
3 A=V/B:A=A+B:GOSUBA:A=VANDE:A=A+B:GOSUBA:PRINT:V=V+1:IFV<>FTHENGOTO3
4 END
16 PRINT"0000";:RETURN
17 PRINT"0001";:RETURN
18 PRINT"0010";:RETURN
19 PRINT"0011";:RETURN
20 PRINT"0100";:RETURN
21 PRINT"0101";:RETURN
22 PRINT"0110";:RETURN
23 PRINT"0111";:RETURN
24 PRINT"1000";:RETURN
25 PRINT"1001";:RETURN
26 PRINT"1010";:RETURN
27 PRINT"1011";:RETURN
28 PRINT"1100";:RETURN
29 PRINT"1101";:RETURN
30 PRINT"1110";:RETURN
31 PRINT"1111";:RETURN

-> 10.3 seconds (~2.4 seconds if you eliminate screen scrolling)
2024-01-19 11:29
Mr SQL

Registered: Feb 2023
Posts: 114
Quoting aeeben
10 TI$="000000":E=15:DIMB$(E):SYS58692:FORA=.TOE:READB$(A):NEXT:D=1/A
20 FORA=.TO255:PRINTB$(A*D)B$(AANDE):NEXT:PRINTTI/60:DATA0000,0001,0010
30 DATA0011,0100,0101,0110,0111,1000,1001,1010,1011,1100,1101,1110,1111

-> 11.8166667 sec.

Multiply by 1/16 is a bit faster than division. Constants in variables is a bit faster. I didn't see any gains from using a subroutine.


Great solutions! I ran this at 11.5 seconds.

But when I added the decimal form and the spaces from Robin's example it went up to 14.5

10ti$="000000":e=15:dimb$(e):sys58692:fora=0toe:readb$(a):next:d=1/a
20 fora=0to255:? a;" ";b$(a*d)b$(a and e):next:printti/60:data0000,0001,0010
30data0011,0100,0101,0110,0111,1000,1001,1010,1011,1100,1101,1110,1111

Probably casting a as a string would improve this time, the print routine handles strings faster than numeric variables.

Bunny BASIC is faster than CBM BASIC for being integer based.
Previous - 1 | 2 | 3 | 4 - Next
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
Vg Vox/Voxvideogame
Sentinel/Excess/TREX
Guests online: 119
Top Demos
1 Next Level  (9.8)
2 Mojo  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Comaland 100%  (9.6)
6 No Bounds  (9.6)
7 Uncensored  (9.6)
8 Wonderland XIV  (9.6)
9 Memento Mori  (9.6)
10 Bromance  (9.5)
Top onefile Demos
1 It's More Fun to Com..  (9.7)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.5)
5 TRSAC, Gabber & Pebe..  (9.5)
6 Rainbow Connection  (9.5)
7 Wafer Demo  (9.5)
8 Dawnfall V1.1  (9.5)
9 Quadrants  (9.5)
10 Daah, Those Acid Pil..  (9.5)
Top Groups
1 Nostalgia  (9.3)
2 Oxyron  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 Crest  (9.3)
Top Musicians
1 Vincenzo  (9.8)
2 Rob Hubbard  (9.7)
3 Stinsen  (9.7)
4 Jeroen Tel  (9.6)
5 Linus  (9.6)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.077 sec.