4 ms·
It took me some time to get why this is faster than simply poking in a for-next loop - nice hack (for those who don't know I can recommend one of Ben Eater's la
by haspok 2y ago
It took me some time to get why this is faster than simply poking in a for-next loop - nice hack (for those who don't know I can recommend one of Ben Eater's latest BASIC hacking videos)!
But why add only 1 character each time, why not add the string to itself? That would grow it exponentially and would require much fewer steps. Or is string concatenation much slower than character concatenation?
- bsdetector 2y agoThe 1..125 loop stores 8000 bytes of string and they need to clear 8000 bytes. There may be a fast path for adding one character, but in any case bytes of program are a valuable resource with only 64k ram so having a second loop from nearest power of two to 8000 would be a waste of bytes.
- badmintonbaseba 2y agoToo much growth can be a problem too, according to this other article strings are at most 255 bytes long: https://retro64.altervista.org/blog/garbage-collection-commodore-64-basic-to-handle-it/ https://retro64.altervista.org/blog/garbage-collection-commo... Which would limit the loop to 1 + 2 + 4 ... 128 = 255. You could start off with this, but making it work and filling exactly 8000 might be too complicated.