LoginLogin

Does division and multiplication affect performance in Smile?

Root / Programming Questions / [.]

Gaelstrom_ValenceCreated:
Reading through a bunch of bresenham algorithm tutorials, trying to find one I could fully understand, one thing I kept seeing was to avoid floating point variables and division. I've been using decimals and division liberally so far and haven't noticed anything, but if I were to make a bigger project, is that something that would affect us?

It shouldn't matter too much

There comes a noticeable difference when you start to make bigger projects. With floating point variables, it probably wouldn't matter given their small size in memory, but if you were to dimension a really large array in floating point, and regularly manipulate that array in your program, you could possibly run into some slowdowns. For the sake of ensuring speed (given that SmileBASIC is a really slow language), I always try to use the integer suffix on variables I know will always need to be integer.

There comes a noticeable difference when you start to make bigger projects. With floating point variables, it probably wouldn't matter given their small size in memory, but if you were to dimension a really large array in floating point, and regularly manipulate that array in your program, you could possibly run into some slowdowns. For the sake of ensuring speed (given that SmileBASIC is a really slow language), I always try to use the integer suffix on variables I know will always need to be integer.
Aight! I'll keep that in mind. Also, do you know if functions tend to be intensive if you were to run them in big for loops?

Aight! I'll keep that in mind. Also, do you know if functions tend to be intensive if you were to run them in big for loops?
Do you mean that you're worried about writing your own functions because of the speed hit? If so, I advise against worrying. Don't sacrifice readability and good code structure until you absolutely have to. If you're talking about the built-in functions, those are all exceptionally fast compared to even a few lines of your own SB code due to the 'runtime' or whatever they're using to run your code.