login
March 19, 2024, 02:20:44 am

Author Topic: Measuring ping jitter in Squirrel  (Read 3138 times)

0 Members and 1 Guest are viewing this topic.

stormeus

  • Vice Underdog
  • Crazy Man
  • *
  • *
  • Posts: 1755
  • Country: us
  • VC:MP Developer
    • View Profile
    • GTA VICE CITY Respective owner
Measuring ping jitter in Squirrel
« on: August 16, 2016, 08:47:39 pm »
This is a small snippet I wrote for the VCDC server which would measure a player's latency jitter. Pingtest.net defines jitter as:
Quote
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.

Code: (Jitter calculation functions) [Select]
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 cases
Code: [Select]
sq>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
Winner Winner x 1 Informative Informative x 1 Useful Useful x 9 (list)
Agree Disagree Funny Winner Pwnt Informative Friendly Useful Optimistic Artistic Late Brain Donor

<krystianoo> stormeus do good job
<krystianoo> with recent update
<krystianoo> if not agree; jeb yourself in head
<Avenger> yesterday you said death to stormeus
<karan> double standard krystianoo
<karan> he called him fake prophet too
<krystianoo> sure fake prophet
<krystianoo> but with recent updates real

Thijn

  • Forum Administrator
  • Crazy Man
  • *
  • *
  • *
  • Posts: 2946
  • Country: nl
    • View Profile
Re: Measuring ping jitter in Squirrel
« Reply #1 on: August 17, 2016, 06:04:29 am »
Nice snippet :)

Might be useful for people to mention what kind of values should be seen as high jitter.
Agree Disagree Funny Winner Pwnt Informative Friendly Useful Optimistic Artistic Late Brain Donor

I'm not totally useless,
I can be used as an bad example ;)

"Never do Today, What you can do Tomorrow"


Roystang

  • Vice Underdog
  • Crazy Man
  • *
  • *
  • *
  • *
  • *
  • Posts: 1403
  • Country: 00
  • rerere
    • View Profile
Re: Measuring ping jitter in Squirrel
« Reply #2 on: August 17, 2016, 02:04:26 pm »
Great Work !
Agree Disagree Funny Winner Pwnt Informative Friendly Useful Optimistic Artistic Late Brain Donor



VCDC 6 Admin/Designer, VW8 Designer, VW9 Mod/Designer, VCDM Developer, VCCNR Admin, EG-A.D Moderator, RTV/TDW Admin

SanaullaH

  • Crazy Man
  • *****
  • Posts: 857
  • Country: pk
  • You're the boss from you , we learn
    • View Profile
Re: Measuring ping jitter in Squirrel
« Reply #3 on: August 17, 2016, 02:59:51 pm »
Agree Disagree Funny Winner Pwnt Informative Friendly Useful Optimistic Artistic Late Brain Donor


RoyStang's Art

krystianoo

  • Crazy Man
  • *****
  • Posts: 1203
  • Country: pl
    • View Profile
Re: blablabla
« Reply #4 on: August 18, 2016, 07:58:06 am »
nice
now fix tommy face
top fun + coach 2 seats only BUG

« Last Edit: December 06, 2016, 02:30:21 pm by krystianoo »
Agree Agree x 1 Funny Funny x 5 Optimistic Optimistic x 1 (list)
Agree Disagree Funny Winner Pwnt Informative Friendly Useful Optimistic Artistic Late Brain Donor


QarZ

  • Crazy Man
  • *****
  • Posts: 635
  • Country: pk
  • you won't be able to think about anyone other than
    • View Profile
Re: Measuring ping jitter in Squirrel
« Reply #5 on: August 18, 2016, 01:47:35 pm »
Nice job
Brain Donor Brain Donor x 2 (list)
Agree Disagree Funny Winner Pwnt Informative Friendly Useful Optimistic Artistic Late Brain Donor