From 21c13e086468758fcae50ee0c8076c2f596bd901 Mon Sep 17 00:00:00 2001 From: nxshock Date: Tue, 8 Mar 2022 17:58:03 +0500 Subject: [PATCH] Separate speed field --- README.md | 1 + gwp.go | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 550c92f..9336f4d 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ func main() { worker := gwp.New(4) // Create pool with specified number of workers worker.ShowProgress = true // Enable progress indicator + worker.ShowProgress = true // Show processing speed in progress indicator worker.EstimateCount = 100 // Set total number on jobs to calculate ETA for i := 0; i < 100; i++ { diff --git a/gwp.go b/gwp.go index ab960eb..38c0225 100644 --- a/gwp.go +++ b/gwp.go @@ -17,6 +17,7 @@ type WorkerPool struct { EstimateCount int ShowProgress bool + ShowSpeed bool processedCount int // processed jobs count errorCount int // processed jobs count that returned error @@ -105,10 +106,17 @@ func (workerPool *WorkerPool) printProgress() { fmt.Fprintf(os.Stderr, " Errors: %d (%.1f%%)", workerPool.errorCount, float64(workerPool.errorCount*100)/float64(workerPool.EstimateCount)) } - if workerPool.EstimateCount > 0 && workerPool.currentSpeed > 0 { - fmt.Fprintf(os.Stderr, " ETA: %s at %.2f rps", - fmtDuration(time.Second*time.Duration(float64(workerPool.EstimateCount-workerPool.processedCount)/workerPool.currentSpeed)), workerPool.currentSpeed) + + if workerPool.currentSpeed > 0 { + if workerPool.EstimateCount > 0 { + fmt.Fprintf(os.Stderr, " ETA: %s", fmtDuration(time.Second*time.Duration(float64(workerPool.EstimateCount-workerPool.processedCount)/workerPool.currentSpeed))) + } + + if workerPool.ShowSpeed { + fmt.Fprintf(os.Stderr, "Speed: %.2f rps", workerPool.currentSpeed) + } } + fmt.Fprint(os.Stderr, endLine) }