如何估计下载剩余时间(精确)? [英] How to estimate download time remaining (accurately)?

查看:283
本文介绍了如何估计下载剩余时间(精确)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当然,你可以将余下的文件的大小由当前的下载速度,但如果你的下载速度波动(它会),这不会产生一个非常好的结果。什么是用于生产顺畅倒计时更好的算法?

Sure you could divide the remaining file size by the current download speed, but if your download speed fluctuates (and it will), this doesn't produce a very nice result. What's a better algorithm for producing smoother countdowns?

推荐答案

这是均线是伟大的本。它提供了一种方法来平滑你的平均,这样每次添加一个新的样本上了年纪的样品成为整体平均递减重要。它们仍然被认为是,但其重要性脱落指数 - 由此得名。而且,由于这是一个移动平均而言,你只需要保持周围一个单一的数字。

An exponential moving average is great for this. It provides a way to smooth your average so that each time you add a new sample the older samples become decreasingly important to the overall average. They are still considered, but their importance drops off exponentially--hence the name. And since it's a "moving" average, you only have to keep a single number around.

在测量下载速度的背景下,公式是这样的:

In the context of measuring download speed the formula would look like this:

averageSpeed = SMOOTHING_FACTOR * lastSpeed + (1-SMOOTHING_FACTOR) * averageSpeed;

SMOOTHING_FACTOR 是一个介于0和1。此数字越高,越快较旧的样本被丢弃。正如你可以在公式中看到,当 SMOOTHING_FACTOR 1,你只是用你的最后一个观察值。当 SMOOTHING_FACTOR 0 averageSpeed​​ 永远不会改变。所以,你想要的东西之间​​,通常一个较低的值来获得体面的平滑。我发现,0.005提供的平均下载速度为pretty的良好的平滑值。

SMOOTHING_FACTOR is a number between 0 and 1. The higher this number, the faster older samples are discarded. As you can see in the formula, when SMOOTHING_FACTOR is 1 you are simply using the value of your last observation. When SMOOTHING_FACTOR is 0 averageSpeed never changes. So, you want something in between, and usually a low value to get decent smoothing. I've found that 0.005 provides a pretty good smoothing value for an average download speed.

lastSpeed​​ 是最后测得的下载速度。您可以通过运行一个计时器每一秒左右来计算,因为你运行它是最后一次了多少字节下载获取此值。

lastSpeed is the last measured download speed. You can get this value by running a timer every second or so to calculate how many bytes have downloaded since the last time you ran it.

averageSpeed​​ 很明显是要用于计算您的预计剩余时间的数量。初始化这首 lastSpeed​​ 测量你。

averageSpeed is, obviously, the number that you want to use to calculate your estimated time remaining. Initialize this to the first lastSpeed measurement you get.

这篇关于如何估计下载剩余时间(精确)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆