Variable or Variable%... Which is faster?

Previous topic - Next topic



Variable or Variable%... Which is faster?

In only need numbers 0-255.

:giveup: - Desarrollo videojuegos Indie · Pixel-Art · Retroinformática · Electrónica Development Indie Videogames · Pixel-Art · Retrocomputing · Electronic


Integers are usually slightly faster, esp. on mobile platforms but most modern CPUs have excellent FPUs for dealing with floats, so its not easy to give a definitive answer. Also, if it needs a lot of integer, float type conversions later in the program, any gain could easily be lost. I use var% for loops, iterators, indexers etc. and try to keep it as a good habit but I always keep one eye on these variables to see if they are sharing values with floats at a later point.

BTW, I suppose you could use the C type "char" to store just a byte(eg: "var AS char"), it's not a documented feature but GLBasic can use some other non-standard basic types IIRC.


"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

Ian Price

Both measurements and opinions are invalid - measurements change between machines and opinions always differ  :D :P

Just do what works for you on your machine and hope that it does something similar on everyone else's! ;) :P
I came. I saw. I played.


Well, I certainly don't see how ints could be slower than floats, so I guess why not. That being said I bet there are other areas in your code which may be more meaningful to optimize.