Well, I was going to say that yes, VSizeSq is more efficient than VSize, because VSize does a square root, which I thought was relatively costly. But I decided to test it:
exec function TestSqrt()
{
local int i, Reps;
local vector RandVect;
local int Year, Month, DayOfWeek, Day, Hour, Min, Sec, MSec, StartTime, EndTime, ElapsedTime;
local float VectSize;
Reps = 100000;
GetSystemTime(Year, Month, DayOfWeek, Day, Hour, Min, Sec, MSec);
StartTime = (Min * 60000) + (Sec * 1000) + MSec;
for(i=0; i<Reps; i++)
{
RandVect.X = FRand() * 100;
RandVect.Y = FRand() * 100;
RandVect.Z = FRand() * 100;
VectSize = VSize(RandVect);
}
GetSystemTime(Year, Month, DayOfWeek, Day, Hour, Min, Sec, MSec);
EndTime = (Min * 60000) + (Sec * 1000) + MSec;
ElapsedTime = EndTime - StartTime;
Log(self $ ".TestSqrt(): Elapsed time for " $ i $ "x VSize(): " $ ElapsedTime $ " msec");
GetSystemTime(Year, Month, DayOfWeek, Day, Hour, Min, Sec, MSec);
StartTime = (Min * 60000) + (Sec * 1000) + MSec;
for(i=0; i<Reps; i++)
{
RandVect.X = FRand() * 100;
RandVect.Y = FRand() * 100;
RandVect.Z = FRand() * 100;
VectSize = VSizeSq(RandVect);
}
GetSystemTime(Year, Month, DayOfWeek, Day, Hour, Min, Sec, MSec);
EndTime = (Min * 60000) + (Sec * 1000) + MSec;
ElapsedTime = EndTime - StartTime;
Log(self $ ".TestSqrt(): Elapsed time for " $ i $ "x VSizeSq(): " $ ElapsedTime $ " msec");
}
And on an i7-12700k, neither loop takes more than about 8 or 9 milliseconds, and they take about the same amount of time. So on a new processor, VSize isn’t a problem and there doesn’t seem to be any difference in performance. Maybe there’s a difference on older processors though.
Anyone got some old hardware they want to try that on?