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:
parent
5b2fc6d56d
commit
21c13e0864
@ -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++ {
|
||||
|
14
gwp.go
14
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)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user