GLBasic forum

Main forum => GLBasic - en => Topic started by: Hark0 on 2012-Sep-23

Title: Variable or Variable%... Which is faster?
Post by: Hark0 on 2012-Sep-23
Hi!

Variable or Variable%... Which is faster?

In only need numbers 0-255.

:giveup:
Title: Re: Variable or Variable%... Which is faster?
Post by: bigsofty on 2012-Sep-23
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.
Title: Re: Variable or Variable%... Which is faster?
Post by: Ian Price on 2012-Sep-23
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
Title: Re: Variable or Variable%... Which is faster?
Post by: Falstaff on 2012-Sep-25
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.