07-01-2024, 05:00 AM
Folks ask this type of question all the time, and it's always hard to give them a solution without seeing their existing code.
Are you wanting to improve file access time in your program? Are you using OPEN file$ FOR INPUT, with LINE INPUT? A simple change to OPEN file$ FOR BINARY would probably be 100 times faster. Reading the whole file at once and just parsing it would be even faster.
Is the issue with the graphics being too slow? Try to convert to Hardware images. Still got issues? Convert the code so the screen only updates the portions that change and leave the rest alone.
Are you having issues with strings? Be certain to add the small strings before worrying over adding large strings.
x$ = large_string + small_string + small_string + small_string + small_string <-- like here.
As written, the above goes left to right, with large + small = large. + small = large. + small = large... It's allocating large amounts of memory, adding/moving the contents of those other two strings into that new block of memory, and then freeing that large/small block of memory.
x$ = large_string + (small_string + small_string + small_string + small_string) <-- this simple change is going to be faster as it's creating, moving, and freeing smaller blocks of memory, before finally merging with that large block.
x$ = large_string + ((small_string + small_string) + (small_string + small_string)) <-- and this will probably be even more efficient for the same reason.
Biggest factor for speed??
REMOVE AS MUCH AS POSSBLE FROM LOOPS!!
for y = 1 to 10000
For x = 1 to 10000
_memput m, m.offset + (y * 1000 + x) * 4, kolor as unsigned long
Next x, y
^That's going to be quite inefficient. How about this?
for y = 1 to 10000000 STEP 1000
For x = 1 to 10000
_memput m, m.offset + (y + x) * 4, kolor as unsigned long
Next x, y
See that's one less math calculation inside the loop? Let's keep going...
for y = 4 to 40000000 STEP 4000
For x = 4 to 40000 STEP 4
_memput m, m.offset + y + x, kolor as unsigned long
Next x, y
Less math to do inside the loop there! Can we keep going??
for y = 4 to 40000000 STEP 4000
For x = m.offset + 4 to m.offset + 40000 STEP 4
_memput m, y + x, kolor as unsigned long
Next x, y
Well my goodness!! Those FOR statements are certainly a little more complex than before, but the math we're actually doing inside that loop now is simple as heck! This loop is going to be a TON faster than the previous one!
Mt personal advice? Write the code to start with. Get things working -- even if they work slow. Only worry about optomizing for speed once you determine where the bottlenecks might be.
Are you wanting to improve file access time in your program? Are you using OPEN file$ FOR INPUT, with LINE INPUT? A simple change to OPEN file$ FOR BINARY would probably be 100 times faster. Reading the whole file at once and just parsing it would be even faster.
Is the issue with the graphics being too slow? Try to convert to Hardware images. Still got issues? Convert the code so the screen only updates the portions that change and leave the rest alone.
Are you having issues with strings? Be certain to add the small strings before worrying over adding large strings.
x$ = large_string + small_string + small_string + small_string + small_string <-- like here.
As written, the above goes left to right, with large + small = large. + small = large. + small = large... It's allocating large amounts of memory, adding/moving the contents of those other two strings into that new block of memory, and then freeing that large/small block of memory.
x$ = large_string + (small_string + small_string + small_string + small_string) <-- this simple change is going to be faster as it's creating, moving, and freeing smaller blocks of memory, before finally merging with that large block.
x$ = large_string + ((small_string + small_string) + (small_string + small_string)) <-- and this will probably be even more efficient for the same reason.
Biggest factor for speed??
REMOVE AS MUCH AS POSSBLE FROM LOOPS!!
for y = 1 to 10000
For x = 1 to 10000
_memput m, m.offset + (y * 1000 + x) * 4, kolor as unsigned long
Next x, y
^That's going to be quite inefficient. How about this?
for y = 1 to 10000000 STEP 1000
For x = 1 to 10000
_memput m, m.offset + (y + x) * 4, kolor as unsigned long
Next x, y
See that's one less math calculation inside the loop? Let's keep going...
for y = 4 to 40000000 STEP 4000
For x = 4 to 40000 STEP 4
_memput m, m.offset + y + x, kolor as unsigned long
Next x, y
Less math to do inside the loop there! Can we keep going??
for y = 4 to 40000000 STEP 4000
For x = m.offset + 4 to m.offset + 40000 STEP 4
_memput m, y + x, kolor as unsigned long
Next x, y
Well my goodness!! Those FOR statements are certainly a little more complex than before, but the math we're actually doing inside that loop now is simple as heck! This loop is going to be a TON faster than the previous one!
Mt personal advice? Write the code to start with. Get things working -- even if they work slow. Only worry about optomizing for speed once you determine where the bottlenecks might be.