计算每秒字节数(平滑方式) [英] Calculating bytes per second (the smooth way)

查看:207
本文介绍了计算每秒字节数(平滑方式)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种解决方案来计算重复调用的函数(下文)的每秒传输的字节数。由于它的不准确性,我不要 想简单地将发送的字节除以所用的总时间:它导致在运行几分钟后无法显示快速的速度变化。

I am looking for a solution to calculate the transmitted bytes per second of a repeatedly invoked function (below). Due to its inaccuracy, I do not want to simply divide the transmitted bytes by the elapsed overall time: it resulted in the inability to display rapid speed changes after running for a few minutes.

预设(大约每50ms调用一次):

The preset (invoked approximately every 50ms):

function uploadProgress(loaded, total){
    var bps = ?;
    $('#elem').html(bps+' bytes per second');
};



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