From c08b41b5296be79b0add1b887a10d293c5269b34 Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Sun, 17 Nov 2019 09:38:11 -0800 Subject: [PATCH] show the final it/s too --- examples/go.mod | 6 +++--- examples/go.sum | 15 +++++++-------- progressbar.go | 8 +++----- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/examples/go.mod b/examples/go.mod index 16cb7f7..ea022de 100644 --- a/examples/go.mod +++ b/examples/go.mod @@ -4,7 +4,7 @@ go 1.12 require ( github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213 - github.com/mattn/go-isatty v0.0.8 // indirect - github.com/schollz/progressbar/v2 v2.14.0 - golang.org/x/sys v0.0.0-20190602015325-4c4f7f33c9ed // indirect + github.com/mattn/go-isatty v0.0.10 // indirect + github.com/schollz/progressbar/v2 v2.14.1 + golang.org/x/sys v0.0.0-20191115151921-52ab43148777 // indirect ) diff --git a/examples/go.sum b/examples/go.sum index 3b12905..45d6ca8 100644 --- a/examples/go.sum +++ b/examples/go.sum @@ -3,18 +3,17 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213 h1:qGQQKEcAR99REcMpsXCp3lJ03zYT1PkRd3kQGPn9GVg= github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213/go.mod h1:vNUNkEQ1e29fT/6vq2aBdFsgNPmy8qMdSay1npru+Sw= -github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE= -github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-isatty v0.0.10 h1:qxFzApOv4WsAL965uUPIsXzAKCZxN2p9UqdhFS4ZW10= +github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ= github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/schollz/progressbar/v2 v2.14.0 h1:vo7bdkI9E4/CIk9DnL5uVIaybLQiVtiCC2vO+u9j5IM= -github.com/schollz/progressbar/v2 v2.14.0/go.mod h1:6YZjqdthH6SCZKv2rqGryrxPtfmRB/DWZxSMfCXPyD8= +github.com/schollz/progressbar/v2 v2.14.1 h1:eT4hzP05ZMx9j4aQpZf3SMG/GnUzWZWpn0DoLJJHxyY= +github.com/schollz/progressbar/v2 v2.14.1/go.mod h1:UdPq3prGkfQ7MOzZKlDRpYKcFqEMczbD7YmbPgpzKMI= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 h1:DH4skfRX4EBpamg7iV4ZlCpblAHI6s6TDM39bFZumv8= -golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190602015325-4c4f7f33c9ed h1:uPxWBzB3+mlnjy9W58qY1j/cjyFjutgw/Vhan2zLy/A= -golang.org/x/sys v0.0.0-20190602015325-4c4f7f33c9ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191115151921-52ab43148777 h1:wejkGHRTr38uaKRqECZlsCsJ1/TGxIyFbH32x5zUdu4= +golang.org/x/sys v0.0.0-20191115151921-52ab43148777/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/progressbar.go b/progressbar.go index bf3290e..8336ed0 100644 --- a/progressbar.go +++ b/progressbar.go @@ -421,7 +421,9 @@ func renderProgressBar(c config, s state) (int, error) { bytesString := "" averageRate := average(s.counterLastTenRates) - if len(s.counterLastTenRates) == 0 { + if len(s.counterLastTenRates) == 0 || s.finished { + // if no average samples, or if finished, + // then average rate should be the total rate averageRate = float64(s.currentNum) / time.Since(s.startTime).Seconds() } @@ -438,10 +440,6 @@ func renderProgressBar(c config, s state) (int, error) { // add on bytes string if max bytes option was set kbPerSecond := averageRate / float64(c.max) * float64(c.maxBytes) / 1000.0 - if s.finished { - // if finished then show the overall time taken - kbPerSecond = float64(c.maxBytes) / 1000.0 / time.Since(s.startTime).Seconds() - } if kbPerSecond > 1000.0 { bytesString = fmt.Sprintf("(%2.1f MB/s)", kbPerSecond/1000.0)