verigak / progress

Easy to use progress bars for Python
ISC License
1.41k stars 179 forks source link

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

Open danizen opened 2 years ago

danizen commented 2 years ago

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:

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 commented 2 years ago

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)