Noob Method Question:- Ignoring Return
BlitzMax Forums/BlitzMax Beginners Area/Noob Method Question:- Ignoring Return
| ||
For resons I dont want to go into I have a Create Method Template of;Method Set:TTheType (ParamList:Various) Self.AllTheFields = ParamList Return Self EndMethodSo, Im sitting in my code and I make a new TTheType by MyOneOfThese:TTheType = New TTheType.Set(ParamList)Ok. So assume that that bit is fine, and I dont change it. However I want somtimes to simple change all the fields, so I do this MyOneOfThese.Set (NewParamList) Now the questions, Concept question: If Im not allocating the "Self" returned from Set:TTheType, was it passed to me, or did the compiler not bother? Aplication Question; If I had a Method that didnt return Self, (SetNoReturn for example), but did the same thing. Would that method run quicker? |
| ||
There's a slight difference in time over 10000s of iterations between capturing the return and letting it drop. Not returning anything gives same time as returning but not capturing. Type ttest Field x Method set(x) x = x ' Return Self End Method End Type mynew:TTest = New ttest t1=MilliSecs() For x = 0 To 10000000 mynew.set(6) Next t2=MilliSecs() 'For x = 0 To 10000000 'myold:TTest = mynew.set(6) 'Next 't3 = MilliSecs() Print (t2-t1) '+ " " + (t3-t2) |
| ||
Right, soType ttest Field x:Int Method set:ttest(x) x = x Return Self End Method End TypeIs infact quicker than Type ttest Field x:Int Method set(x) x = x End Method End TypeThis was infact what I was getting, but I didnt understand why. Basicaly it means that any member Method that isnt going to return anything should be optimised by making it return the type. And for the life of me, I cannot understand why, and so am loath to take advantage of it. Edit: Its only a bit quicker, so its an "On adverage" quicker, over say 10 runs. Still wierd tho |
| ||
Not sure what results you got. Mine suggested no difference between 'return but drop' and not returning self and a very slight difference 4 ms over 10 million iterations. |
| ||
On adverage, ~10 ms increase in speed on "return but drop" over dont return. I know this is an arbitary speed increase, but as I was worried that it would be a decrease in speed, this 10ms is still good. (10ms out of 150) |