diff --git a/Misc/Benchmarking.go b/Misc/Benchmarking.go index a07f678..2d12bf5 100644 --- a/Misc/Benchmarking.go +++ b/Misc/Benchmarking.go @@ -10,6 +10,8 @@ type BenchmarkResult struct { Iterations Collections.List[time.Duration] Average time.Duration Median time.Duration + Min time.Duration + Max time.Duration } func Benchmark(name string, iterations int, f func()) *BenchmarkResult { @@ -48,4 +50,6 @@ func (this *BenchmarkResult) Calculate() { } }) this.Median = this.Iterations.Get(this.Iterations.Size() / 2) + this.Min = this.Iterations.Get(0) + this.Max = this.Iterations.Get(this.Iterations.Size() - 1) } diff --git a/Tests/Misc/Benchmarking_test.go b/Tests/Misc/Benchmarking_test.go new file mode 100644 index 0000000..6a49ea9 --- /dev/null +++ b/Tests/Misc/Benchmarking_test.go @@ -0,0 +1,19 @@ +package Misc + +import ( + "github.com/RENCI/GoUtils/Misc" + "github.com/stretchr/testify/assert" + "math/rand" + "testing" + "time" +) + +func Test_Benchmark(t *testing.T) { + + res := Misc.Benchmark("random sleep", 10, func() { + r := rand.Intn(400) + time.Sleep(time.Duration(r) * time.Millisecond) + }) + res.Calculate() + assert.NotNil(t, res) +}