more things

This commit is contained in:
cubixle
2021-07-27 21:09:29 +01:00
parent 2ddeeea267
commit cb8d79fca3
7 changed files with 196 additions and 46 deletions
+87 -9
View File
@@ -1,26 +1,104 @@
package l1
type Results struct {
import "fmt"
type results struct {
Target string
Count int
Results []Result
Results []*Result
totalCompletedTime float64
successfulCount int
errorCount int
}
type Result struct {
// CompletedIn is in seconds
CompletedIn int
RunTime int64
CompletedIn float64
Error error
StatusCode int
}
func (r *Results) RequestsPerMin() int {
totalCompletedIn := 0
func (r *results) RequestPerSecond() float64 {
totalCompletedIn := float64(0)
for _, res := range r.Results {
if res.Error != nil {
continue
}
totalCompletedIn += res.CompletedIn
}
return totalCompletedIn / r.Count
return float64(len(r.Results)) / totalCompletedIn
}
func (r *Results) AvgCompletionTime() int {
return 0
func (r *results) PeakResponseTime() {
}
func (r *results) ErrorCount() int {
if r.errorCount > 0 {
return r.errorCount
}
for _, res := range r.Results {
if res.Error == nil {
continue
}
r.errorCount++
}
return r.errorCount
}
func (r *results) SuccessfulCount() int {
if r.successfulCount > 0 {
return r.successfulCount
}
for _, res := range r.Results {
if res.Error != nil {
continue
}
r.successfulCount++
}
return r.successfulCount
}
func (r *results) AvgResponseTime() float64 {
totalCompletedIn := float64(0)
for _, res := range r.Results {
if res.Error != nil {
continue
}
totalCompletedIn += res.CompletedIn
}
return totalCompletedIn / float64(len(r.Results))
}
func (r *results) CompletedTime() float64 {
if r.totalCompletedTime > 0 {
return r.totalCompletedTime
}
for _, res := range r.Results {
if res.Error != nil {
continue
}
r.totalCompletedTime += res.CompletedIn
}
return r.totalCompletedTime
}
func (r *results) Print() {
fmt.Println("-----------------------------------------------------------")
fmt.Println("| L1 load tester.")
fmt.Println("| Default result printer.")
fmt.Println("-----------------------------------------------------------")
fmt.Println("")
fmt.Printf("Load testing %s\n", r.Target)
fmt.Println("")
fmt.Printf("Request per second: %.2f\n", r.RequestPerSecond())
fmt.Printf("Average response time: %.2f seconds\n", r.AvgResponseTime())
fmt.Printf("Success count: %d\n", r.SuccessfulCount())
fmt.Printf("Error count: %d\n", r.ErrorCount())
fmt.Println("")
}