aboutsummaryrefslogtreecommitdiffstats
path: root/bench_test.go
diff options
context:
space:
mode:
authorRose Hogenson <rosehogenson@posteo.net>2026-05-30 13:32:08 -0700
committerRose Hogenson <rosehogenson@posteo.net>2026-05-30 13:32:08 -0700
commit3730a6e124fd0ce550501dff0367cacfcacb83d9 (patch)
tree423e5f4e59e645aac014c57b953def93e9b5ca15 /bench_test.go
parent0c6cb370056bdef55fdfef8d543ee4daf2dadf8a (diff)
downloadimgutil-3730a6e124fd0ce550501dff0367cacfcacb83d9.tar.zst
Add a benchmark for quickSelect
Diffstat (limited to 'bench_test.go')
-rw-r--r--bench_test.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/bench_test.go b/bench_test.go
new file mode 100644
index 0000000..1047865
--- /dev/null
+++ b/bench_test.go
@@ -0,0 +1,22 @@
+package main
+
+import (
+ "cmp"
+ "math/rand/v2"
+ "testing"
+)
+
+func BenchmarkQuickSelect(b *testing.B) {
+ r := rand.New(rand.NewPCG(0, 0))
+ testSlice := make([]int, 3840*2160)
+ for i := range testSlice {
+ testSlice[i] = r.Int()
+ }
+ myTestSlice := make([]int, len(testSlice))
+ for b.Loop() {
+ b.StopTimer()
+ copy(myTestSlice, testSlice)
+ b.StartTimer()
+ quickSelect(myTestSlice, len(myTestSlice)/2, cmp.Compare)
+ }
+}