From 3730a6e124fd0ce550501dff0367cacfcacb83d9 Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Sat, 30 May 2026 13:32:08 -0700 Subject: Add a benchmark for quickSelect --- bench_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 bench_test.go 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) + } +} -- cgit v1.3.1