Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idea to expose duration of a progress/infinite as a feature #100

Open
danizen opened this issue Jan 19, 2022 · 1 comment
Open

Idea to expose duration of a progress/infinite as a feature #100

danizen opened this issue Jan 19, 2022 · 1 comment

Comments

@danizen
Copy link

danizen commented Jan 19, 2022

I noticed in much of the code where I use progress, I also give some feedback about throughput and duration.
I tried to recode this so that I was delegating this to the Progress/Infinite object, but two basic problems prevented this:

  1. The elapsed property is cast to int so that it cannot be used for accurate duration and throughput calculations
  2. The "timer" keeps running after the progress has been finished.

A solution to both is as follows:

  • use monotonic() when finish method is called and initialize an attribute called end_ts
  • add a duration attribute that returns self.end_ts - self.start_ts, and is not cast to int
  • document that users should used duration rather than elapsed

I also wonder whether you should switch to perf_counter() from monotonic() at this point, but I am not sure whether in CPython or pypy there is any practical difference.

@danizen
Copy link
Author

danizen commented Jan 19, 2022

The API exposed would enable this sort of output:

    progress.finish()
    count = progress.index
    duration = progress.duration
    tput = count / duration

    print(f'\nProcessed {count} records in {duration:.1f} seconds ({tput:.1f} per second)', file=sys.stderr)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant