package main import "github.com/montanaflynn/stats" /** 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 } func keepTotal(timesChan chan float64, errorChan chan bool, endChan chan bool) ([]float64, int) { var timesSlice []float64 var errorRate int end := false for { if end { break } select { case timeValue := <-timesChan: timesSlice = append(timesSlice, timeValue) case <-errorChan: errorRate++ case <-endChan: if len(errorChan) == 0 && len(timesChan) == 0 { end = true } } } return timesSlice, errorRate }