June 19, 2018, 03:04:27 am

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

0 Members and 1 Guest are viewing this topic.

stormeus

  • Vice Underdog
  • Crazy Man
  • *
  • *
  • Posts: 1750
  • Country: us
  • VC:MP Developer
    • View Profile
    • GTA VICE CITY Respective owner
    • Awards
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 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: 2821
  • Country: nl
    • View Profile
    • Awards
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

  • Crazy Man
  • *****
  • Posts: 475
  • Country: sa
  • You , again?
    • View Profile
    • Awards
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

[UFt] [UFr] [UF]


SanaullaH

  • VW7 - The Night Wolves
  • Crazy Man
  • *
  • Posts: 433
  • Country: pk
  • You're the boss from you , we learn
    • View Profile
    • Awards
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

Credits RoyStang / RavenouZ

krystianoo

  • Vice War Staff
  • Crazy Man
  • *
  • *
  • Posts: 950
  • Country: pl
    • View Profile
    • Awards
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 4 Optimistic Optimistic x 1 (list)
Agree Disagree Funny Winner Pwnt Informative Friendly Useful Optimistic Artistic Late Brain Donor


QarZ

  • VW7 - The Night Wolves
  • Crazy Man
  • *
  • Posts: 397
  • Country: pk
  • you won't be able to think about anyone other than
    • View Profile
    • Awards
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

Where is the Stupid FLAG