RaidersClamoring Posted October 26, 2022 Share Posted October 26, 2022 A question about pros and cons of writing variables to memory vs skipping those and putting the same data directly into function calls -- Would there be a difference in speed of execution (big enough to become a consideration when calls begin piling up) between the two examples below and by extension entire scripts leaning more toward one approach over the other: Float Dist1 = GetDistanceBetweenPoints(Subj.x, Point1x, Subj.y, Point1y, NewZ1, NewZ1) Float Dist2 = GetDistanceBetweenPoints(Subj.x, Point2x, Subj.y, Point2y, NewZ2, NewZ2) Float AngX = Subj.GetAngleX() Vals[1] = atan(ZDiff1/Dist1) Vals[2] = atan(ZDiff2/Dist2) Vals[0] = AngX Return Vals Vals[1] = atan(ZDiff1/GetDistanceBetweenPoints(Subj.x, Point1x, Subj.y, Point1y, NewZ1, NewZ1)) Vals[2] = atan(ZDiff2/GetDistanceBetweenPoints(Subj.x, Point2x, Subj.y, Point2y, NewZ2, NewZ2)) Vals[0] = Subj.GetAngleX() Return Vals ? The top one obviously has better readability which makes production easier but perhaps there's a big enough gain in efficiency to sometimes use the eye-bleeding style instead. Link to comment Share on other sites More sharing options...
SKKmods Posted October 26, 2022 Share Posted October 26, 2022 Whilst there must be some overhead in a variable assignment, it is not measurable so I would prioritize code maintainability over compact notation. Altho the second version is actually more readable for me :O Infact if the compiler is sufficiently clever it could (we dont know) concantenate the calls in pcode anyway. Link to comment Share on other sites More sharing options...
Recommended Posts