Optimization

BlitzMax Forums/BlitzMax Programming/Optimization

Wow this topic has really taken off on the academic/belief side of things so lets get back to basics...

Type TString
	Field Chars:Byte[]
	Field NumChars:Int
	Method Write()
		Local LoopVar:Int
		For LoopVar = 0 To NumChars
			Print Chr(Chars[LoopVar])
		Next
	End Method
End Type

testLoopMax = 999999

start = MilliSecs()

For loopy = 0 To testLoopMax
	Hello:TString = New TString
	Hello.NumChars = 4
	Hello.Chars = [Byte(Asc("H")),Byte(Asc("e")),Byte(Asc("l")),Byte(Asc("l")),Byte(Asc("o"))]
	'Hello.Write()
Next

time1 = MilliSecs()-start

start = MilliSecs()

For loopy2 = 0 To testLoopMax
	Hello2:String = "Hello"
	'Print Hello2
Next

time2 = MilliSecs()-start

Print "TString Hello x "+(testLoopMax+1)+" = "+time1+"ms"
Print "String  Hello x "+(testLoopMax+1)+" = "+time2+"ms"



Gives the following results on a 800 Mhz Athlon ;o)

TString Hello x 1000000 = 1243ms
String  Hello x 1000000 = 2ms


Does this answer the original question, or should we be storing our Bytes in a linked list?