Skip to content

Commit

Permalink
colblk: fix for BenchmarkUnsafeIntegerSlice
Browse files Browse the repository at this point in the history
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)
```
  • Loading branch information
RaduBerinde committed Aug 14, 2024
1 parent a6d2952 commit 25ac678
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion sstable/colblk/unsafe_slice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package colblk

import (
"fmt"
"io"
"math"
"testing"
"time"
Expand Down Expand Up @@ -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)
})
}

0 comments on commit 25ac678

Please sign in to comment.