This is a small snippet I wrote for the VCDC server which would measure a player's latency
jitter. Pingtest.net defines jitter as:
the variance in measuring successive ping tests. Zero jitter means the results were exactly the same every time, and anything above zero is the amount by which they varied.
Which makes it a decent measure of the
instability of a player's connection. In VCDC, a player would be kicked not only due to high ping, but also due to a high jitter and consistently unstable connection that could cause warping.
The code below calculates the
standard deviation of an array of ping measurements to find jitter.
function CalculateAvg(arr) {
local sum = 0, count = 0;
foreach(entry in arr) {
sum += entry;
count++;
}
return sum.tofloat() / count.tofloat();
}
function CalculateVariance(arr) {
local avg = CalculateAvg(arr);
local sum = 0, count = 0;
foreach (entry in arr) {
sum += pow(entry - avg, 2);
count++;
}
return sum.tofloat() / count.tofloat();
}
function CalculateJitter(arr) {
return sqrt(CalculateVariance(arr));
}
Test casessq>print(CalculateJitter([250, 280, 230, 240, 250, 290, 240, 310, 230, 250]));
25.7099
sq>print(CalculateJitter([10, 10, 15, 10, 10, 12, 10, 9, 10, 10]));
1.62481
sq>print(CalculateJitter([80, 80, 80, 350, 360, 320, 330, 167, 95, 80]));
121.974
sq>print(CalculateJitter([5, 10, 15, 20, 25, 30, 35, 40, 45]));
12.9099