-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #108 from glensc/measure-speed
Feature: Measure speed of downloads
- Loading branch information
Showing
5 changed files
with
40 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from __future__ import annotations | ||
|
||
from contextlib import contextmanager | ||
from time import monotonic | ||
from typing import TYPE_CHECKING | ||
|
||
from humanize import naturalsize | ||
|
||
if TYPE_CHECKING: | ||
from pathlib import Path | ||
|
||
|
||
@contextmanager | ||
def measure_speed(part: Path): | ||
start = monotonic() | ||
print(f"Downloading: {part}") | ||
yield | ||
now = monotonic() | ||
file_size = part.stat().st_size | ||
rate = file_size / (now - start) | ||
speed = naturalsize(rate, binary=True) | ||
|
||
print(f"Downloaded in {speed}/s: {part}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters