1
0
mirror of https://github.com/nxshock/gwp.git synced 2024-11-27 03:31:02 +05:00

Separate speed field

This commit is contained in:
nxshock 2022-03-08 17:58:03 +05:00
parent 5b2fc6d56d
commit 21c13e0864
2 changed files with 12 additions and 3 deletions

View File

@ -30,6 +30,7 @@ func main() {
worker := gwp.New(4) // Create pool with specified number of workers worker := gwp.New(4) // Create pool with specified number of workers
worker.ShowProgress = true // Enable progress indicator 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 worker.EstimateCount = 100 // Set total number on jobs to calculate ETA
for i := 0; i < 100; i++ { for i := 0; i < 100; i++ {

14
gwp.go
View File

@ -17,6 +17,7 @@ type WorkerPool struct {
EstimateCount int EstimateCount int
ShowProgress bool ShowProgress bool
ShowSpeed bool
processedCount int // processed jobs count processedCount int // processed jobs count
errorCount int // processed jobs count that returned error errorCount int // processed jobs count that returned error
@ -105,10 +106,17 @@ func (workerPool *WorkerPool) printProgress() {
fmt.Fprintf(os.Stderr, " Errors: %d (%.1f%%)", fmt.Fprintf(os.Stderr, " Errors: %d (%.1f%%)",
workerPool.errorCount, float64(workerPool.errorCount*100)/float64(workerPool.EstimateCount)) 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", if workerPool.currentSpeed > 0 {
fmtDuration(time.Second*time.Duration(float64(workerPool.EstimateCount-workerPool.processedCount)/workerPool.currentSpeed)), workerPool.currentSpeed) 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) fmt.Fprint(os.Stderr, endLine)
} }