Jump to content
Sign in to follow this  

Moving Average

Recommended Posts


Calculation for the Moving Average transfer speed. It calculates the average of speed samples taken approx over the last 5 seconds.

#include <Array.au3>

Func MovingAverage() ; updates stats during download
    Dim $SpeedSamples[5]
    $Accuracytimer = timerInit() ; for first loop

    While @InetGetActive
    $CalcAverage = 0

    $BytesRead1 = @InetGetBytesRead
    $BytesRead2 = @InetGetBytesRead

    _ArrayPush($SpeedSamples,Int($BytesRead2 - $BytesRead1)*(TimerDiff($Accuracytimer)/1000))
    $Accuracytimer = timerInit()
    $Ubound = Ubound($SpeedSamples) -1
    For $x = 0 To $Ubound
        $CalcAverage += $SpeedSamples[$x]
        $CalcAverage = $CalcAverage/$Ubound
        $AverageSpeed = Int($CalcAverage/1024)

    ConsoleWrite($AverageSpeed&" kb/s"&@CRLF)

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this