package main import ( "github.com/montanaflynn/stats" "time" ) /** intToFloat takes []int64 and converts it to []float64 for processing */ func intToFloat(times []int64) []float64 { var floatArray []float64 for timeRange := range times { floatArray = append(floatArray, float64(timeRange)) } return floatArray } /** getResponseTimes takes a list of ints and returns mean, stddev, 95p, 99p Uses stats library to calculate mean, stddev, 95p, 99p */ func getResponseTimes(times []float64) (float64, float64, float64, float64) { mean, _ := stats.Mean(times) stddev, _ := stats.StandardDeviation(times) perc99, _ := stats.Percentile(times, 99.00) perc95, _ := stats.Percentile(times, 95.00) return mean, stddev, perc99, perc95 } /** keepTotal takes several channels and keeps a running total of duration and errors */ func keepTotal(timesChan chan time.Duration, errorChan chan bool, endChan chan bool, totalTimeChan chan []int64, totalErrorChan chan int) { var timesSlice []int64 var errorRate int end := false for { if end { break } select { case timeValue := <-timesChan: typedTimeValue := int64(1) * timeValue.Microseconds() timesSlice = append(timesSlice, typedTimeValue) case <-errorChan: errorRate += 1 case <-endChan: if len(errorChan) == 0 && len(timesChan) == 0 { end = true } } } totalTimeChan <- timesSlice totalErrorChan <- errorRate }