Time cost of simple function/method calls

BlitzMax Forums/BlitzMax Programming/Time cost of simple function/method calls

Try it?

Just time 100,000 iterations of both.

[edit]
I get about 5ms difference over 1,000,000 iterations. Sometimes the first test is faster, sometimes the second. So, no difference worth worrying about.

Global t:tMyType = New tMyType
Global n:Int
Global s:Int

s = MilliSecs()
For n = 1 To 1000000
   t.DoStuff()
Next
s = MilliSecs() - s
Print "First test: " + s + "ms"

s = MilliSecs()
For n = 1 To 1000000
   t.DoStuff2()
Next
s = MilliSecs() - s
Print "Second test: " + s + "ms"
End



Type TMyType
	
	Field somefield:Int
		
		Method GetSomeField()
			
			Return somefield
			
		End Method
		
		Method DoStuff:String()
			
			Return (Pi * GetSomeField() + " " + GetSomeField())
			
		End Method
		
		
		Method DoStuff2:String()
			
			Return (Pi * somefield + " " + somefield)
			
		End Method
End Type