Hmm, which is faster?

BlitzMax Forums/BlitzMax Programming/Hmm, which is faster?

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.

Hmm, interesting test result BrEgOrS, although your test doesn't exactly replicate the scenario I was envisioning, because in your 'local version' you still only declare the local variable once and then enter the for loop (and only call the method once). The scenario I was curious about would be where the method would be called 1000's of times and each time it would allocate/de-allocate a local.

Anyhow, I tried running your test code as is and got results similar to yours although reversed (the field method was slightly faster, although not significant).

However, when I switched the code to more closely match my scenario, the local version was almost 4x faster!

Try running this code and let me know what you get for results.
Type TestType1

	Method TestMethod1()
		
		
		Local now = MilliSecs()
		For Local n=1 To 100000000
			Local TestInt
			TestInt = (2*TestInt+10)/13.0*1000-1
		Next
		now = MilliSecs()-now
		Print "TestMethod1 time: "+now
		
	End Method

End Type

Type TestType2

	Field TestInt

	Method TestMethod2()
		
		Local now = MilliSecs()
		For Local n=1 To 100000000
			TestInt = (2*TestInt+10)/13.0*1000-1
		Next
		now = MilliSecs()-now
		Print "TestMethod2 time: "+now
		
	End Method

End Type


t1:TestType1 = New TestType1
t2:TestType2 = New TestType2

t1.TestMethod1()
t2.TestMethod2()


My results were as follows:
TestMethod1 time: 5317
TestMethod2 time: 19058 (yeah, my comp sucks)