Skip to content

Commit

Permalink
Added test, Min, Max for Benchmarking
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimir2217 committed Feb 4, 2025
1 parent 424fac0 commit 8d97ccd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Misc/Benchmarking.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
19 changes: 19 additions & 0 deletions Tests/Misc/Benchmarking_test.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 8d97ccd

Please sign in to comment.