cmd/torrent/main.go | 8 ++++++-- diff --git a/cmd/torrent/main.go b/cmd/torrent/main.go index 385d732cae02bb34dad192f844f0263794d3d72e..f27a8538cbb570986b6b7a05f1e29e5562b7a712 100644 --- a/cmd/torrent/main.go +++ b/cmd/torrent/main.go @@ -42,7 +42,8 @@ <-t.GotInfo() } lastStats := t.Stats() var lastLine string - for range time.Tick(time.Second) { + interval := 3 * time.Second + for range time.Tick(interval) { var completedPieces, partialPieces int psrs := t.PieceStateRuns() for _, r := range psrs { @@ -54,6 +55,9 @@ partialPieces += r.Length } } stats := t.Stats() + byteRate := int64(time.Second) + byteRate *= stats.BytesReadUsefulData.Int64() - lastStats.BytesReadUsefulData.Int64() + byteRate /= int64(interval) line := fmt.Sprintf( "%v: downloading %q: %s/%s, %d/%d pieces completed (%d partial): %v/s\n", time.Since(start), @@ -63,7 +67,7 @@ humanize.Bytes(uint64(t.Length())), completedPieces, t.NumPieces(), partialPieces, - humanize.Bytes(uint64(stats.BytesReadUsefulData.Int64()-lastStats.BytesReadUsefulData.Int64())), + humanize.Bytes(uint64(byteRate)), ) if line != lastLine { lastLine = line