blob: ade43e9d7881fafd43178928944a335036d318c1 (
plain) (
blame)
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
|
//go:build (amd64 || arm64 || riscv64) && !purego
package proto
import (
"bytes"
"crypto/sha256"
"testing"
"github.com/stretchr/testify/require"
)
func TestColRawOf(t *testing.T) {
testColumn[[16]byte](t, "byte_arr_16", func() ColumnOf[[16]byte] {
return &ColRawOf[[16]byte]{}
}, [16]byte{1: 1}, [16]byte{10: 14})
require.Equal(t, ColumnType("FixedString(32)"), (ColRawOf[[32]byte]{}).Type())
require.Equal(t, ColumnType("FixedString(2)"), (ColRawOf[[2]byte]{}).Type())
}
func BenchmarkColRawOf_EncodeColumn(b *testing.B) {
const rows = 1_000
data := ColRawOf[[32]byte]{}
for i := 0; i < rows; i++ {
h := sha256.Sum256([]byte("ClickHouse не тормозит"))
data.Append(h)
}
var buf Buffer
data.EncodeColumn(&buf)
b.SetBytes(int64(len(buf.Buf)))
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
buf.Reset()
data.EncodeColumn(&buf)
}
}
func BenchmarkColRawOf_DecodeColumn(b *testing.B) {
const rows = 1_000
data := ColRawOf[[32]byte]{}
for i := 0; i < rows; i++ {
h := sha256.Sum256([]byte("ClickHouse не тормозит"))
data.Append(h)
}
var buf Buffer
data.EncodeColumn(&buf)
br := bytes.NewReader(buf.Buf)
r := NewReader(br)
dec := ColRawOf[[32]byte]{}
if err := dec.DecodeColumn(r, rows); err != nil {
b.Fatal(err)
}
b.SetBytes(int64(len(buf.Buf)))
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
br.Reset(buf.Buf)
r.raw.Reset(br)
dec.Reset()
if err := dec.DecodeColumn(r, rows); err != nil {
b.Fatal(err)
}
}
}
|