-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.go
39 lines (31 loc) · 1.09 KB
/
benchmark.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package parquetwg
import (
"context"
"math"
"testing"
"github.com/prometheus/prometheus/storage"
"github.com/prometheus/prometheus/util/teststorage"
"github.com/thanos-io/objstore"
)
// QueryCreateFunc is a callback to create a Queryable from a pre-filled TestStorage. It may or may not use the provided Bucket.
// If the provided bucket is used, it will be used to measure object storage operations or to inject latency.
type QueryCreateFunc func(tb testing.TB, bkt objstore.Bucket, st *teststorage.TestStorage) storage.Queryable
func RunBenchmarks(b *testing.B, f QueryCreateFunc) {
ctx := context.Background()
// Example trivial function, add more below for interesting scenarios
b.Run("simple", func(bb *testing.B) {
st := teststorage.New(bb)
bb.Cleanup(func() { _ = st.Close() })
bkt := objstore.NewInMemBucket()
bb.Cleanup(func() { _ = bkt.Close() })
q, err := f(bb, bkt, st).Querier(math.MinInt64, math.MaxInt64)
if err != nil {
bb.Fatal("error building querier: ", err)
}
bb.ReportAllocs()
bb.ResetTimer()
for i := 0; i < b.N; i++ {
q.Select(ctx, false, nil)
}
})
}