Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Bytes slower than integers

Author
Message
Jambo B
16
Years of Service
User Offline
Joined: 17th Sep 2009
Location: The Pit
Posted: 14th Aug 2011 14:51
I wondered about using bytes to store smaller values rather than integers, so I tried a speed test first with a byte:



...and then with an integer:



(Uses Matrix plugins)

On my system, the byte code took an average of 4700 ms. to complete. The integer code took 4000 ms.

I'm a bit surprised about this! Why does that happen? Wondered if any of you technical-minded people knew.

James.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 14th Aug 2011 15:01
My guess is that bytes are implemented as integers so a lot of additional conversion work is going on when you use bytes.
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 14th Aug 2011 15:19
So are you saying it's better to just use integers rather than bytes?

TheComet

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 14th Aug 2011 15:54
In DBPro possibly.

However, bytes can make coding simpler at times. For example, bytes automatically wrap round to 0 after 255:

Webber
15
Years of Service
User Offline
Joined: 27th May 2011
Location:
Posted: 15th Aug 2011 01:16
That's interesting. I better stick with integers then.
For some unknown reason, Booleans are the same as bytes in DBPro.
I wonder if using Booleans instead of bytes would run faster then integers?

I like games, and stuff.
Kevin Picone
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 15th Aug 2011 01:41
also, in the expression if (byByte = 255), DBpro is probably treating 255 as an integer and not a byte here. So the byte side of the expression is probably being recast to integer during the compare, making the comparison conceptually if (int(bybyte)=255)

Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 15th Aug 2011 04:53
I never use booleans because they take the same amount in a file as a byte (just 1 byte) and having a switch with 256 different possibilities is better than just a boolean switch with 0 or 1.

The way I see it we should all use the right data type for the job. If your variable is never going over 255 then use a byte. If it's never going over 65,535 then use a word and so on.



Benjamin
23
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 15th Aug 2011 04:58
It's much more efficient to use integers over bytes/words/dwords, in DBPro at least.



Support a charitable indie game project!
Burning Feet Man
18
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 16th Aug 2011 06:58
Grog Grueslayer, could you update that chart with Boolean as well?

Cheers,
BFM

Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 16th Aug 2011 09:40
Actually it's not my chart... I copied it from the Darkbasic Pro help files but I've been thinking of making my own version.

Webber is right in Darkbasic booleans act like bytes with a limit of 0 to 255.



Jambo B
16
Years of Service
User Offline
Joined: 17th Sep 2009
Location: The Pit
Posted: 16th Aug 2011 16:51
After reading all the responses, I think I'm leaning towards using only integers in loops which need to be efficient.
miso
16
Years of Service
User Offline
Joined: 16th Jun 2010
Location: Budapest, Hungary, 127.0.0.1
Posted: 17th Aug 2011 09:05
I think its not dbpro specific. When you do calculations with your variables, your computer has to make conversions to 32 bit format, if your variables are different. Integers in dbpro are signed longs, so they need no further conversion in a 32 bit system, so theyre a bit quicker. It also works the same way in c++.

The speed increase is not truely big, so you have to choose what do you need more badly. A tiny speed increase or storage size. (signed longs are 4 times bigger in memory than a byte)

No place like 127.0.0.1 .

Login to post a reply

Server time is: 2026-07-11 03:38:30
Your offset time is: 2026-07-11 03:38:30