From c0d67882bbf44e7c4e080abddda80435aa8b604f Mon Sep 17 00:00:00 2001 From: derrod Date: Fri, 16 Sep 2022 13:09:39 +0200 Subject: [PATCH] [utils] Replace some instances of time() with perf_counter() In these cases only relative time is important, and sufficiently fast computers could run into zero division errors. --- legendary/utils/lfs.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/legendary/utils/lfs.py b/legendary/utils/lfs.py index cae16b7..74b4cbc 100644 --- a/legendary/utils/lfs.py +++ b/legendary/utils/lfs.py @@ -7,7 +7,7 @@ import logging from pathlib import Path from sys import stdout -from time import time +from time import perf_counter from typing import List, Iterator from legendary.models.game import VerifyResult @@ -115,7 +115,7 @@ def validate_files(base_path: str, filelist: List[tuple], hash_type='sha1', stdout.write('\n') show_progress = True interval = (_size / (1024 * 1024)) // 100 - start_time = time() + start_time = perf_counter() with open(full_path, 'rb') as f: real_file_hash = hashlib.new(hash_type) @@ -125,7 +125,7 @@ def validate_files(base_path: str, filelist: List[tuple], hash_type='sha1', if show_progress and i % interval == 0: pos = f.tell() perc = (pos / _size) * 100 - speed = pos / 1024 / 1024 / (time() - start_time) + speed = pos / 1024 / 1024 / (perf_counter() - start_time) stdout.write(f'\r=> Verifying large file "{file_path}": {perc:.0f}% ' f'({pos / 1024 / 1024:.1f}/{_size / 1024 / 1024:.1f} MiB) ' f'[{speed:.1f} MiB/s]\t')