-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgorilla_bench_test.go
More file actions
141 lines (120 loc) · 2.89 KB
/
gorilla_bench_test.go
File metadata and controls
141 lines (120 loc) · 2.89 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package benchmarks
import (
"io"
"math/rand/v2"
"testing"
"time"
"github.com/prometheus/prometheus/tsdb/chunkenc"
"github.com/stretchr/testify/require"
"github.com/fpetkovski/tscodec-go/alp"
"github.com/fpetkovski/tscodec-go/dod"
)
func BenchmarkFloats(b *testing.B) {
const numSamples = 120
var (
t = time.Now().UnixMilli()
v = float64(10_000)
tsArray [numSamples]int64
vsArray [numSamples]float64
)
ts := tsArray[:numSamples]
vs := vsArray[:numSamples]
for i := range numSamples {
ts[i] = t + int64(15_000*i) + int64(rand.Float64()*100)
vs[i] = v + float64(i+1000) + rand.Float64()*100
}
b.Run("gorilla", func(b *testing.B) {
b.Run("encode", func(b *testing.B) {
b.ReportAllocs()
b.SetBytes(numSamples * 16)
for b.Loop() {
chk := chunkenc.NewXORChunk()
app, err := chk.Appender()
require.NoError(b, err)
for i := range ts {
app.Append(ts[i], vs[i])
}
b.ReportMetric(float64(len(chk.Bytes())), "compressed_bytes")
}
})
b.Run("decode", func(b *testing.B) {
b.ReportAllocs()
chk := chunkenc.NewXORChunk()
app, err := chk.Appender()
require.NoError(b, err)
for i := range ts {
app.Append(ts[i], vs[i])
}
b.SetBytes(int64(len(chk.Bytes())))
for b.Loop() {
it := chk.Iterator(nil)
for it.Next() != chunkenc.ValNone {
_, _ = it.At()
}
}
})
})
b.Run("alp", func(b *testing.B) {
b.Run("encode", func(b *testing.B) {
b.ReportAllocs()
b.SetBytes(numSamples * 16)
tsc := make([]byte, numSamples*8)
fsc := make([]byte, numSamples*8)
for b.Loop() {
tsc = dod.EncodeInt64(tsc, ts)
fsc = alp.Encode(fsc, vs)
b.ReportMetric(float64(len(tsc)+len(fsc)), "compressed_bytes")
}
})
b.Run("alp-decode", func(b *testing.B) {
b.ReportAllocs()
tsc := dod.EncodeInt64(nil, ts)
fsc := alp.Encode(nil, vs)
b.SetBytes(int64(len(fsc) + len(tsc)))
var (
ints dod.Int64Block
floats [numSamples]float64
)
for b.Loop() {
_ = dod.DecodeInt64(ints[:], tsc)
_ = alp.Decode(floats[:], fsc)
}
})
})
b.Run("alp-stream", func(b *testing.B) {
b.Run("encode", func(b *testing.B) {
b.SetBytes(numSamples * 16)
b.ReportAllocs()
for b.Loop() {
tsc := dod.EncodeInt64(nil, ts)
fsc := alp.StreamEncode(nil, vs, 16)
b.ReportMetric(float64(len(tsc)+len(fsc)), "compressed_bytes")
}
})
b.Run("decode", func(b *testing.B) {
b.ReportAllocs()
tsc := dod.EncodeInt64(nil, ts)
fsc := alp.StreamEncode(nil, vs, 8)
b.SetBytes(int64(len(fsc) + len(tsc)))
const chunkSize = 10
var (
ints dod.Int64Block
floatsDst [chunkSize]float64
)
alpDecoder := alp.StreamDecoder{}
for b.Loop() {
_ = dod.DecodeInt64(ints[:], tsc)
alpDecoder.Reset(fsc, 8)
for {
_, err := alpDecoder.Decode(floatsDst[:])
if err == io.EOF {
break
}
if err != nil {
b.Fatal(err)
}
}
}
})
})
}