diff --git a/Makefile b/Makefile index 4825ebc..42bcfa8 100644 --- a/Makefile +++ b/Makefile @@ -2,3 +2,10 @@ default: test test: go test -v -count=1 ./... + +fmt: + go fmt ./... + +lint: + golangci-lint run + sh -c 'test -z "$$(gofmt -l .)"' diff --git a/bench.go b/bench.go index d57efbf..8274ff9 100644 --- a/bench.go +++ b/bench.go @@ -16,6 +16,7 @@ type TimingResult struct { Max time.Duration Mean time.Duration Median time.Duration + StdDev time.Duration StartTime time.Time EndTime time.Time Duration time.Duration @@ -25,8 +26,25 @@ type TimingResult struct { // String returns a formatted string representation of the TimingResult. func (r TimingResult) String() string { return fmt.Sprintf( - "Start Time: %v, End Time: %v, Duration: %v, Iterations: %d, Min: %v, Max: %v, Mean: %v, Median: %v", - r.StartTime, r.EndTime, r.Duration, r.Iterations, r.Min, r.Max, r.Mean, r.Median, + "Timing Results:\n"+ + "Start Time: %v\n"+ + "End Time: %v\n"+ + "Total Duration: %v\n"+ + "Iterations: %d\n"+ + "Min Duration: %v\n"+ + "Max Duration: %v\n"+ + "Mean Duration: %v\n"+ + "Median Duration: %v\n"+ + "Standard Deviation: %v\n", + r.StartTime.Format(time.RFC3339), + r.EndTime.Format(time.RFC3339), + r.Duration, + r.Iterations, + r.Min, + r.Max, + r.Mean, + r.Median, + r.StdDev, ) } @@ -63,12 +81,14 @@ func TimeFunction(ctx context.Context, fn func() error, iterations int) (TimingR max := time.Duration(times[len(times)-1]) mean := time.Duration(stat.Mean(times, nil)) median := time.Duration(stat.Quantile(0.5, stat.Empirical, times, nil)) + stdDev := time.Duration(stat.StdDev(times, nil)) return TimingResult{ Min: min, Max: max, Mean: mean, Median: median, + StdDev: stdDev, StartTime: startTime, EndTime: endTime, Duration: totalDuration, diff --git a/bench_test.go b/bench_test.go index 3454086..222e690 100644 --- a/bench_test.go +++ b/bench_test.go @@ -59,7 +59,6 @@ func quickSort(arr []int) { for i := range arr { if arr[i] < arr[right] { - arr[i], arr[left] = arr[left], arr[i] left++ }