mirror of
https://github.com/cubixle/l1.git
synced 2026-05-01 00:48:44 +01:00
more things
This commit is contained in:
+87
-9
@@ -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("")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user