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

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

问题描述

确定您可以将剩余的文件大小除以当前的下载速度,但如果您的下载速度波动(将会),则不会产生非常好的结果。什么是更好的算法来产生更平滑的倒计时?

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 指数移动平均线是非常好的。它提供了一种平滑您的平均值的方式,以便每次添加新样本时,较旧的样本对于整体平均值而言变得越来越重要。他们仍然被考虑,但它们的重要性依次下降 - 因此名称。而且由于它是一个移动的平均值,你只需要保留一个数字。

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.

在测量下载速度的上下文中,公式如下所示: p>

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为平均下载速度提供了非常好的平滑值。

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天全站免登陆