tags:

views:

88

answers:

1

Hello.

I have an OnRecv() function that is randomly called with random chunks of data. Is it any easy way to calculate median speed for last second? It may be near any number of calls per second - from 0-1 to 10000+. Programming language is irrelevant.

+2  A: 

Look on wikipedia at quantiles to get the full spiel on how to calculate but it depends on how many samples you take for the speed.

For example you take five readings like this

235, 427, 354, 846, 457

you order them by the magnitude to get

235, 354, 427, 457, 846

then the median speed would be 427. For an even number of samples it is the mean of the two middle samples.

This is based on very simple assumptions, please don't give me loads of grief if this is not detailed enough.

In short though there doesn't seem to be a quick way apart from in R programming language, don't know much about this though.

Mark Dickinson
So i must keep a list of packets arrived last second? In order to do it i will need a list of time-packet pairs and recalculate such list on any packet arrived. Seems like a lot of things to do :(
Eye of Hell
Yeah, but you could create an object to represent the time and packet, then if you were in C# say, you could use a lambda to get an ordered list of these, it speeds things up a bit. :|
Mark Dickinson
Other thing is, I wonder how useful the median is for your application. You could just keep a running total of speed, and divide by the number of packets to get the mean speed value.
Mark Dickinson