schollz / progressbar

A really basic thread-safe progress bar for Golang applications
https://pkg.go.dev/github.com/schollz/progressbar/v3?tab=doc
MIT License
4.08k stars 220 forks source link

Estimated time remaining does not take into account current iteration #105

Closed tchajed closed 1 week ago

tchajed commented 3 years ago

Re-rendering the bar in the middle of an iteration updates the time since start, but the time remaining doesn't take into account the current iteration.

Here's a simple example video, and the code to generate it below. The rate is a constant 1 it/s, but progress comes in some large spurts. I have a goroutine rendering the bar regularly to keep the output up-to-date.

package main

import (
    "time"

    "github.com/schollz/progressbar/v3"
)

func main() {
    bar := progressbar.NewOptions(10, progressbar.OptionSetPredictTime(true))
    go func() {
        for !bar.IsFinished() {
            bar.RenderBlank()
            time.Sleep(65 * time.Millisecond)
        }
    }()
    time.Sleep(1 * time.Second)
    bar.Add(1)
    time.Sleep(5 * time.Second)
    bar.Add(5)
    time.Sleep(4 * time.Second)
    bar.Add(4)
    bar.Finish()
}
schollz commented 2 years ago

Could you please submit a PR to fix?