Skip to content

Commit

Permalink
GODRIVER-2907 Use median ops/sec
Browse files Browse the repository at this point in the history
  • Loading branch information
prestonvasquez committed Sep 17, 2024
1 parent 58eea79 commit 8f56eee
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions x/mongo/driver/mongocrypt/binary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"os"
"path"
"runtime"
"sort"
"testing"
"time"

Expand Down Expand Up @@ -151,6 +152,17 @@ func newCryptForBench(b *testing.B) *MongoCrypt {
return crypt
}

func calcMedian(values []float64) float64 {
sort.Float64s(values)

n := len(values)
if n%2 == 0 {
return (values[n/2-1] + values[n/2]) / 2.0
}

return values[(n-1)/2]
}

func BenchmarkBulkDecryption(b *testing.B) {
const numKeys = 1500
const repeatCount = 10
Expand Down Expand Up @@ -180,7 +192,7 @@ func BenchmarkBulkDecryption(b *testing.B) {
// Run the benchmark. Repeat benchmark for thread counts: (1, 2, 8, 64).
// Repeat 10 times.
for _, bench := range benchmarks {
var totalOpsPerSec float64
var opsPerSec []float64

b.Run(fmt.Sprintf("threadCount=%v", bench.threads), func(b *testing.B) {
runtime.GOMAXPROCS(bench.threads)
Expand All @@ -197,11 +209,10 @@ func BenchmarkBulkDecryption(b *testing.B) {
}
})

totalOpsPerSec += float64(b.N) / time.Now().Sub(startTime).Seconds()
opsPerSec = append(opsPerSec, float64(b.N)/time.Now().Sub(startTime).Seconds())
}
})

avgOpsPerSec := totalOpsPerSec / float64(repeatCount)
b.Logf("thread count: %v, ops/sec: %.2f\n", bench.threads, avgOpsPerSec)
b.Logf("thread count: %v, median ops/sec: %.2f\n", bench.threads, calcMedian(opsPerSec))
}
}

0 comments on commit 8f56eee

Please sign in to comment.