From 25ac6781ae36cfb9c81996d4f2db49fb12379882 Mon Sep 17 00:00:00 2001 From: Radu Berinde Date: Wed, 14 Aug 2024 08:09:56 -0700 Subject: [PATCH] colblk: fix for BenchmarkUnsafeIntegerSlice MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Take the random row index generation out of the measured path. ``` name old time/op new time/op delta UnsafeIntegerSlice/uint64,delta8-10 3.54ns ± 0% 1.25ns ± 1% -64.65% (p=0.029 n=4+4) UnsafeIntegerSlice/uint64,delta4-10 3.44ns ± 0% 0.94ns ± 0% -72.70% (p=0.029 n=4+4) UnsafeIntegerSlice/uint64,delta2-10 3.36ns ± 0% 0.63ns ± 0% -81.36% (p=0.029 n=4+4) UnsafeIntegerSlice/uint64,delta1-10 3.30ns ± 0% 0.63ns ± 1% -80.74% (p=0.029 n=4+4) UnsafeIntegerSlice/uint64,delta0-10 3.30ns ± 1% 0.51ns ± 0% -84.43% (p=0.029 n=4+4) UnsafeIntegerSlice/uint32,delta4-10 3.44ns ± 0% 0.94ns ± 2% -72.55% (p=0.029 n=4+4) UnsafeIntegerSlice/uint32,delta2-10 3.36ns ± 0% 0.63ns ± 1% -81.39% (p=0.029 n=4+4) UnsafeIntegerSlice/uint32,delta1-10 3.34ns ± 3% 0.62ns ± 0% -81.38% (p=0.029 n=4+4) UnsafeIntegerSlice/uint32,delta0-10 3.33ns ± 2% 0.51ns ± 0% -84.80% (p=0.029 n=4+4) UnsafeIntegerSlice/uint16,delta2-10 3.40ns ± 1% 0.64ns ± 5% -81.29% (p=0.029 n=4+4) UnsafeIntegerSlice/uint16,delta1-10 3.30ns ± 0% 0.62ns ± 0% -81.13% (p=0.029 n=4+4) UnsafeIntegerSlice/uint16,delta0-10 3.29ns ± 0% 0.51ns ± 0% -84.63% (p=0.029 n=4+4) UnsafeIntegerSlice/uint8,delta1-10 3.29ns ± 0% 0.62ns ± 0% -81.09% (p=0.029 n=4+4) UnsafeIntegerSlice/uint8,delta0-10 3.30ns ± 0% 0.51ns ± 0% -84.65% (p=0.029 n=4+4) ``` --- sstable/colblk/unsafe_slice_test.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/sstable/colblk/unsafe_slice_test.go b/sstable/colblk/unsafe_slice_test.go index f601d6c787..a3b2983470 100644 --- a/sstable/colblk/unsafe_slice_test.go +++ b/sstable/colblk/unsafe_slice_test.go @@ -6,6 +6,7 @@ package colblk import ( "fmt" + "io" "math" "testing" "time" @@ -46,9 +47,16 @@ func benchmarkUnsafeIntegerSlice[U Uint]( buf := aligned.ByteSlice(int(sz) + 1 /* trailing padding byte */) _ = ub.Finish(0, rows, 0, buf) s, _ := DecodeUnsafeIntegerSlice[U](buf, 0, rows) + var reads [256]int + for i := range reads { + reads[i] = rng.Intn(rows) + } b.ResetTimer() + var result uint8 for i := 0; i < b.N; i++ { - _ = s.At(rng.Intn(rows)) + result ^= uint8(s.At(reads[i&255])) } + b.StopTimer() + fmt.Fprint(io.Discard, result) }) }