如何计算使用flask上传文件所需的时间

如何计算使用flask上传文件所需的时间,flask,file-upload,Flask,File Upload,我想计算使用flask上传文件所需的时间。我已经在before_请求方法中启动了计时器,并尝试使用time.monotic在after_请求中结束它。但是每次上传同一个文件所花的时间都不一样。请求前后的方法是正确的开始和结束位置吗 @app.before_request def before_request(): global request_start_time request_start_time = time.monotonic() print(request_s

我想计算使用flask上传文件所需的时间。我已经在before_请求方法中启动了计时器,并尝试使用time.monotic在after_请求中结束它。但是每次上传同一个文件所花的时间都不一样。请求前后的方法是正确的开始和结束位置吗

@app.before_request
def before_request():
    global  request_start_time
    request_start_time = time.monotonic()
    print(request_start_time)

@app.after_request
def after_request(response):
    global end_time
    global duration, b
    end_time = time.monotonic()
    duration = end_time - request_start_time
    print("speed:", b/duration/100000)
    return response

@app.route('/upload')
def upload():
    return render_template('upload.html')


@app.route('/uploader', methods=['GET', 'POST'])
def uploader():

    global duration,b
    if request.method == 'POST':
        f = request.files['file']
        print("uploader")
        f.save(secure_filename(f.filename))
        b = os.path.getsize(f.filename)

您认为每次上传的持续时间都是相同的,有什么特别的原因吗?你看到了什么样的差异?每次的持续时间都有很大的差异。我正在尝试计算文件上传速度,使用持续时间,速度达到300MBps,这在我的网络中似乎不寻常。您认为每次上传的持续时间都是相同的,有什么特别的原因吗?你看到了什么样的差异?每次的持续时间都有很大的差异。我试图计算文件上传速度,使用持续时间,速度达到300MBps,这在我的网络中似乎不寻常