On Tue, 9 Apr 2002, Hrvoje Niksic wrote:

> > I'll grab the "other" part and explain what curl does. It shows a "current
> > speed" based on the past five seconds,
>
> Does it mean that the speed doesn't change for five seconds, or that you
> always show the *current* speed, but relative to the last five seconds?  I
> may be missing something, but I don't see how to efficiently implement the
> latter.

We store a byte index about once every second (and a time stamp). Then we get
the "current speed" by getting the index difference divided by the time
difference (and before five seconds have elapsed, we base the speed on less
time). The meter is updated maximum once per second, I don't think it makes
sense to update the screen faster than that.

Pseudo code:

 #define PERIOD 6 /* number of seconds to take into account */

 /* once per second */
 counter++

 timebuffer [ counter % PERIOD ] = timenow
 indexbuffer[ counter % PERIOD ] = index

 index_during_period = indexbuffer[ counter % PERIOD ] -
   indexbuffer[ (counter-1) % PERIOD ]

 exact_time_of_period = timebuffer[ counter % PERIOD ] -
   timebuffer[ (counter-1) % PERIOD ]

 speed_during_period = index_during_period / exact_time_of_period


This basicly explains what curl does, not saying it is any particularly
scientific way or anything, I've just found this info interesting.

-- 
      Daniel Stenberg - http://daniel.haxx.se - +46-705-44 31 77
   ech`echo xiun|tr nu oc|sed 'sx\([sx]\)\([xoi]\)xo un\2\1 is xg'`ol

Reply via email to