Type Byte

BlitzMax Forums/BlitzMax Beginners Area/Type Byte

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Why would it need a bound checking?
Its handled the same as on it -> overflow is handled with "entering the lowest posible number" -> 255+1 = 0

Here is a little benchmark code

Rem
	Small benchmarking of byte, short vs int on access and operation
End Rem

Strict


Local bVal:Byte	= 0
Local sVal:Short = 0
Local iVal:Int = 0


Local t1:Int,t2:Int,t3:Int

' Byte test
t1 = MilliSecs()
For Local i:Int = 1 To 100000
	For Local k:Int = 1 To 100
		bVal = (bVal + Rand(1, 1000)) Mod 256
	Next
	For Local k:Int = 1 To 100
		bVal = (bVal * Rand(1, 100)) Mod 256
	Next
	For Local k:Int = 1 To 100
		bVal = (bVal Shl 1) Mod 256
	Next
Next
t1 = MilliSecs() - t1
Print "Byte Operations took: " + t1 + " milliseconds."

' Short test
t2= MilliSecs()
For Local i:Int = 1 To 100000
	For Local k:Int = 1 To 100
		sVal = (sVal + Rand(1, 1000)) Mod 256
	Next
	For Local k:Int = 1 To 100
		sVal = (sVal * Rand(1, 100)) Mod 256
	Next
	For Local k:Int = 1 To 100
		sVal = (sVal Shl 1) Mod 256
	Next
Next
t2 = MilliSecs() - t2
Print "Short Operations took: " + t2 + " milliseconds."

' Int test
t3 = MilliSecs()
For Local i:Int = 1 To 100000
	For Local k:Int = 1 To 100
		iVal = (iVal + Rand(1, 1000)) Mod 256
	Next
	For Local k:Int = 1 To 100
		iVal = (iVal * Rand(1, 100)) Mod 256
	Next
	For Local k:Int = 1 To 100
		iVal = (iVal Shl 1) Mod 256
	Next
Next
t3 = MilliSecs() - t3
Print "Integer Operations took: " + t3 + " milliseconds."


My results:

Byte Operations took: 2545 milliseconds.
Short Operations took: 2616 milliseconds.
Integer Operations took: 2553 milliseconds.



Thing to mention:

I'm working on a Core Duo T2500 @ 2Ghz with fully rebuild modules on most actual GCC version (not the one used with BM originally). So could someone on a regular system (single core, perhaps P4 3ghz or the like without rebuilt modules) test that as well?