However, I've seen it mentioned on here a few times that Long is "native" to QB64 "under the hood" and offers a slight performance benefit over Integer. If this is true, and assuming the extra memory needed for a Long instead of an Integer isn't an issue, do I want to declare my "boolean" variables as type Long rather than Integer?
And in general, other than saving memory, is there any reason you would want to use Integer instead of Long for numeric types where you just need to store values between -32,768 and 32,767 signed or 0-65,535 unsigned?
Much appreciated...
Update: I'd still like to know what people have to say, but it looks like Long does work for boolean, per this test program...
Results: 1. Does Val work with Long? sValue="1256512" iValue=1256512
2. Does type Long work for boolean values? (10 > 5) evaluates to -1 (5 > 10) evaluates to 0 ((2 + 2) = 5) evaluates to 0 ((2 + 2) = 4) evaluates to -1 (5 > 3) Or (2 < 1) evaluates to -1 (5 > 3) And (2 < 1) evaluates to 0
Finished.
Title: Re: integer vs long for boolean variables and performance in general?
Post by: bplus on December 08, 2021, 03:23:45 pm
It is rumored Longs are faster than Integers but of all the things to worry about this isn't one of them. :)
Title: Re: integer vs long for boolean variables and performance in general?
Post by: Cobalt on December 08, 2021, 03:43:01 pm
I'm with Bplus, not really something you need to be fretting over for speed issues.
Personally I use _BYTE for my TRUE\FALSE work. As I see no need to waste extra memory for them(regardless of the trivial-ness of memory consumption anymore).
On a memory note however, I did just run into an issue where one of my programs would have needed little more than ~48gigs of ram to load and run. And how many folk have that in their computer(I don't)? So memory limits can still come back to _byte you if your not careful.
Title: Re: integer vs long for boolean variables and performance in general?
Post by: madscijr on December 08, 2021, 03:56:48 pm
Thanks for clearing that up @bplus and @Cobalt. Makes my life a little easier not having to update 10,000 Integer variables to Long, LoL.
Title: Re: integer vs long for boolean variables and performance in general?
Post by: SMcNeill on December 08, 2021, 04:09:11 pm
Longs, generally are faster than integers, but not by an appreciable amount unless you're doing a lot of heavy math, inside a loop, with a large array of data...
Now, all things being equal, except for my variable types in those 3 loops, the speeds I get are about:
2.5 seconds. 2.4 seconds. 2.2 seconds.
On Win 11, 64-bit OS, compiling with the 64-bit version of QB64, integer64's are the fastest for me, while Longs are a fraction slower, and Integers are just a miniscule slower than that...
But, in the grand scheme of things, it's such a small change here, that it has to be compounded in multiple loops repeatedly before it adds up to anything noticeable. To just compare True/False values, I really don't think it'd ever make much of a difference at all.
Title: Re: integer vs long for boolean variables and performance in general?
Post by: jack on December 08, 2021, 04:57:22 pm
sometimes you get unexpected results, a while ago I run a simple primes benchmark and I thought that long or integer would surely be faster than byte on a 64-bit machine but I was wrong, byte was significantly faster
Title: Re: integer vs long for boolean variables and performance in general?
Post by: OldMoses on December 10, 2021, 07:46:31 am
I've used _BYTE a few times in boolean work, though I was generally unconcerned about speed. It just seems economical. I always assumed that any speed issues were due to a particular data type being "closer to the metal" by matching register sizes better. If that is the case, then _INTEGER64 should be pretty quick on modern systems, but it would seem to be a memory waste for a simple boolean. Not that that is a problem on modern systems either...
Any time I've had speed issues, I can't recall ever changing integer types that made any improvements.