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:
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
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,

View File

@ -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++
}