PHP Code:
float dist[MAXPLAYERS + 1][MAXPLAYERS + 1];
void Distance1()
{
Profiler prof = new Profiler();
prof.Start();
for (int i = 1; i <= MaxClients; ++i) {
if (!IsClientInGame(i)) {
continue;
}
float pos[3];
GetClientEyePosition(i, pos);
for (int j = 1; j <= MaxClients; ++j) {
if (i == j || !IsClientInGame(j)) {
continue;
}
float target[3];
GetClientEyePosition(j, target);
dist[i][j] = GetVectorDistance(pos, target);
}
}
prof.Stop();
PrintToServer("dist1 = %f", prof.Time);
}
void Distance2(bool squared = false)
{
Profiler prof = new Profiler();
prof.Start();
bool validClient[MAXPLAYERS + 1];
float pos[MAXPLAYERS + 1][3];
for (int i = 1; i <= MaxClients; ++i) {
if (!IsClientInGame(i)) {
continue;
}
validClient[i] = true;
GetClientEyePosition(i, pos[i]);
}
for (int i = 1; i <= MaxClients; ++i) {
if (!validClient[i]) {
continue;
}
for (int j = 1; j <= MaxClients; ++j) {
if (i == j || !validClient[j]) {
continue;
}
dist[i][j] = GetVectorDistance(pos[i], pos[j], squared);
}
}
prof.Stop();
PrintToServer("dist2 = %f (%s)", prof.Time, squared ? "squared" : " ");
}
On my laptop: i7 10750H, win10, with srcds and csgo running, (and a lot of other junk), here is what i got, with 48 players in game
dist1 = 0.000151
dist2 = 0.000059 ( )
dist2 = 0.000054 (squared)
The profiler uses QueryPerformanceCounter, thus the result should be enough in this case.
I mean sourcemod JIT is not that bad, and the major overhead is expected to be brand prediction missing and cache missing, not the calculation itself.
Total float operation is 48*48*(3+3) = 13824 (let multiplication and addition be the same), which is not that much at all for a morden cpu.