Decouple Reporters from Attack function
This changeset breaks the API of Attack in order to decouple Reporters and the Attack function. Attack now returns a slice with non-deterministic order of Results which one can use on the calling code with or without Reporters, hence making it much more useful on a library usage setting. These developments could be of interest to issue #11 which was closed in the past.
This commit is contained in:
12
README.md
12
README.md
@@ -97,17 +97,23 @@ import (
|
||||
vegeta "github.com/tsenart/vegeta/lib"
|
||||
"time"
|
||||
"os"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
targets, _ := vegeta.NewTargets([]string{"GET http://localhost:9100/"})
|
||||
rate := uint64(100) // per second
|
||||
duration := 4 * time.Second
|
||||
reporter := vegeta.NewTextReporter()
|
||||
|
||||
vegeta.Attack(targets, rate, duration, reporter)
|
||||
results := vegeta.Attack(targets, rate, duration)
|
||||
|
||||
reporter.Report(os.Stdout)
|
||||
totalTime := time.Duration(0)
|
||||
for _, result := range results {
|
||||
totalTime += result.Timing
|
||||
}
|
||||
meanTime := time.Duration(float64(totalTime) / float64(len(results)))
|
||||
|
||||
fmt.Printf("Average timing: %s", meanTime)
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user