Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Thu Sep 19, 2019 7:51 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: Optimizing for speed using integer datatypes
PostPosted: Thu Sep 16, 2010 11:59 am 
Offline

Joined: Fri Oct 21, 2005 1:35 pm
Posts: 19
Location: Indiana Dunes
I remember, years ago, when I wrote code using Microsoft's Visual Basic 6, the official word from Microsoft was that, for maximum code execution speed, everything should be in long integers (the native datatype of Visual Basic 6). If you used any other integer datatype, the value would have to be translated, at runtime, back to long integers, costing processing speed.

Does REALbasic have this limitation? In other words, for maximum speed, whenever possible, should I try to keep all integer values at a specific datatype? If so, what is it? UInt8? Uint16? UInt32? UInt64? Byte? Int8? Int16? Int32? Int64?

I realize that I could just experiment and discover for myself, but I am hoping that this fact is already known.

Many thanks for the answer.
:?:


Top
 Profile  
Reply with quote  
 Post subject: Re: Optimizing for speed using integer datatypes
PostPosted: Thu Sep 16, 2010 12:15 pm 
Offline
User avatar

Joined: Sun Aug 05, 2007 10:46 am
Posts: 4931
Location: San Diego, CA
In this day and age I doubt there is a definitive answer to your question...

Are you running a 32bit CPU? 64bit?
what about the OS?

etc... etc...

So I'd say stay with INTEGER, as that is the one that RB defines twice.... INTEGER and INT32?

BTW.... the same thing actually affected VB6....

_________________
Dave Sisemore
iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1
Note : I am not interested in any solutions that involve custom Plug-ins of any kind


Top
 Profile  
Reply with quote  
 Post subject: Re: Optimizing for speed using integer datatypes
PostPosted: Thu Sep 16, 2010 12:58 pm 
Offline

Joined: Fri Oct 21, 2005 1:35 pm
Posts: 19
Location: Indiana Dunes
My customers will be using a wide array of CPUs and OSes. Which brings up a second question. If I use UINT64, will the compiled program run on a 32 bit machine?

I don't follow how, just because INTEGER and INT32 has been defined twice, means that it is the fastest datatype.


Top
 Profile  
Reply with quote  
 Post subject: Re: Optimizing for speed using integer datatypes
PostPosted: Thu Sep 16, 2010 1:28 pm 
Offline

Joined: Fri Dec 01, 2006 3:09 pm
Posts: 650
Location: Tennessee, USA
The fact that integers tend to be the fastest data type has nothing to do with the fact that it is defined twice, Integer and Int32. It is based on how the processing of 4 byte integers is done within the CPU.

Unless your program is going to be doing an astronomical amount of calculations I doubt that you have to worry about these things. Today's computers tend to leave those worries behind for the vast majority of programs. So the more important thing is to choose the data type that can best handle the range of values that your program needs to handle.

Also, a Int64 and Uint64 works just fine on a 32 bit machine if you need values of that magnitude. They will be a little bit slower, but as stated before, if you are not doing an astronomical number of calculations, you probably won't notice the difference.


Top
 Profile  
Reply with quote  
 Post subject: Re: Optimizing for speed using integer datatypes
PostPosted: Thu Sep 16, 2010 2:15 pm 
Offline
User avatar

Joined: Wed May 10, 2006 2:42 pm
Posts: 2985
Location: Germany
Calculations with 32 bit integers will be faster on a 32 bit CPU than the same calculations with 16 bit values. The reason is that internally all those values are expanded from 16 to 32 bit and on the result side shrunken to fit in 16 bit.

Greetings
Christian

_________________
See you in Orlando, Florida for Real World 2013
More details and registration here:
http://www.realsoftware.com/community/realworld.php


Top
 Profile  
Reply with quote  
 Post subject: Re: Optimizing for speed using integer datatypes
PostPosted: Thu Sep 16, 2010 5:18 pm 
Offline

Joined: Fri Oct 21, 2005 1:35 pm
Posts: 19
Location: Indiana Dunes
Christian, you say, "Calculations with 32 bit integers will be faster on a 32 bit CPU than the same calculations with 16 bit values."

So can I assume that it would also be true that "Calculations with 64 bit integers will be faster on a 64 bit CPU than the same calculations with 32 bit values"?

By the way, I am doing astronomical amounts of calculations. I'm trying to minimize the processing time.

Thanks for the responses so far!
:D


Top
 Profile  
Reply with quote  
 Post subject: Re: Optimizing for speed using integer datatypes
PostPosted: Thu Sep 16, 2010 5:25 pm 
Offline
User avatar

Joined: Wed May 10, 2006 2:42 pm
Posts: 2985
Location: Germany
Do not optimize without measurement.

64 bit math on a 64 bit CPU may only be faster than 32 bit math if you use 64 bit commands.

Greetings
Christian

_________________
See you in Orlando, Florida for Real World 2013
More details and registration here:
http://www.realsoftware.com/community/realworld.php


Top
 Profile  
Reply with quote  
 Post subject: Re: Optimizing for speed using integer datatypes
PostPosted: Fri Sep 17, 2010 5:39 am 
Offline

Joined: Sat Nov 24, 2007 11:40 am
Posts: 390
Location: Spain
Dunestrider wrote:
By the way, I am doing astronomical amounts of calculations. I'm trying to minimize the
:D

Use a plugin written in Cxx, that's the best (and in some cases the only) option.


Top
 Profile  
Reply with quote  
 Post subject: Re: Optimizing for speed using integer datatypes
PostPosted: Fri Sep 17, 2010 10:48 am 
Offline

Joined: Fri Oct 21, 2005 1:35 pm
Posts: 19
Location: Indiana Dunes
So I did a quick experiment (which I wanted to avoid, that is why I posted my question here). Anyway, here is the results:

1) Using 32 bit integer datatypes is faster than 64 bit integers, even on a 64-bit CPU.
2) 16 and 8 bit integer datatypes caused lockups, even though the variables were all within range.

This is using RB 2010r3, PPC G5

So I think I will stick to 32 bit integers. Unless I'm doing a bitwise op requiring 64 bits.

Thank you for all your comments and suggestions!
:shock:


Top
 Profile  
Reply with quote  
 Post subject: Re: Optimizing for speed using integer datatypes
PostPosted: Sat Sep 18, 2010 1:44 pm 
Offline
User avatar

Joined: Thu Mar 01, 2007 2:02 pm
Posts: 237
Location: Sunny (generally!) Southern California
Your test results don't surprise me at all. Here's why...

When they refer to a 64-bit CPU they mean that the CPU itself has a 64-bit wide internal bus. This will make the internal processing of the CPU faster. However, most systems nowadays have a 32-bit external bus. Thus, data passing to and from the CPU is traveling on a 32-bit wide bus. This means that a 32-bit processor will actually transfer data as fast or faster than a 64-bit processor with 32 bit integers.

So, an 8 or 16-bit integer needs extra time to fill the rest of the bus lines with zeros.
64-bit integers will need extra time because they can only be passed to the CPU in 32-bit wide pieces.
But a 32-bit integer is read and transferred in one piece.

- Dale

(All this from my hardware design days back in the dark ages. :) )

_________________
-----
Real Studio 2012r1 on Windows 7 (64 bit)
-----
It has been said that politics is the second oldest profession.
I have learned that it bears a striking resemblance to the first.
- Ronald Reagan


Top
 Profile  
Reply with quote  
 Post subject: Re: Optimizing for speed using integer datatypes
PostPosted: Sat Sep 18, 2010 2:59 pm 
Offline

Joined: Sat Nov 24, 2007 11:40 am
Posts: 390
Location: Spain
You forget that although the CPU is 64 bit capable, RB program is actually 32 bits. And I guess RB does not translate the operations on 8 and 16 bits to assembler corresponding operators; int8, int16 and int64 are objects based on 32 bit data members.
Well. just my bet, :)


Top
 Profile  
Reply with quote  
 Post subject: Re: Optimizing for speed using integer datatypes
PostPosted: Tue Sep 21, 2010 5:37 pm 
Offline

Joined: Mon Apr 16, 2007 3:12 pm
Posts: 154
RB is 32 bit, if you use 64 bit integers on a 64 bit system, RB will present the integer in 2 halves to the cpu. This will be slower than using a 32 bit integer which is presented in one half.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group