This commit is contained in:
Jeffrey Paul 2024-05-18 18:49:03 -07:00
parent 81b25d1421
commit 82cfc3c88e
3 changed files with 29 additions and 3 deletions

View File

@ -2,3 +2,10 @@ default: test
test: test:
go test -v -count=1 ./... go test -v -count=1 ./...
fmt:
go fmt ./...
lint:
golangci-lint run
sh -c 'test -z "$$(gofmt -l .)"'

View File

@ -16,6 +16,7 @@ type TimingResult struct {
Max time.Duration Max time.Duration
Mean time.Duration Mean time.Duration
Median time.Duration Median time.Duration
StdDev time.Duration
StartTime time.Time StartTime time.Time
EndTime time.Time EndTime time.Time
Duration time.Duration Duration time.Duration
@ -25,8 +26,25 @@ type TimingResult struct {
// String returns a formatted string representation of the TimingResult. // String returns a formatted string representation of the TimingResult.
func (r TimingResult) String() string { func (r TimingResult) String() string {
return fmt.Sprintf( return fmt.Sprintf(
"Start Time: %v, End Time: %v, Duration: %v, Iterations: %d, Min: %v, Max: %v, Mean: %v, Median: %v", "Timing Results:\n"+
r.StartTime, r.EndTime, r.Duration, r.Iterations, r.Min, r.Max, r.Mean, r.Median, "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]) max := time.Duration(times[len(times)-1])
mean := time.Duration(stat.Mean(times, nil)) mean := time.Duration(stat.Mean(times, nil))
median := time.Duration(stat.Quantile(0.5, stat.Empirical, times, nil)) median := time.Duration(stat.Quantile(0.5, stat.Empirical, times, nil))
stdDev := time.Duration(stat.StdDev(times, nil))
return TimingResult{ return TimingResult{
Min: min, Min: min,
Max: max, Max: max,
Mean: mean, Mean: mean,
Median: median, Median: median,
StdDev: stdDev,
StartTime: startTime, StartTime: startTime,
EndTime: endTime, EndTime: endTime,
Duration: totalDuration, Duration: totalDuration,

View File

@ -59,7 +59,6 @@ func quickSort(arr []int) {
for i := range arr { for i := range arr {
if arr[i] < arr[right] { if arr[i] < arr[right] {
arr[i], arr[left] = arr[left], arr[i] arr[i], arr[left] = arr[left], arr[i]
left++ left++
} }