github.com/weaviate/weaviate@v1.24.6/adapters/repos/db/lsmkv/segment_serialization_benchmarks_test.go (about) 1 // _ _ 2 // __ _____ __ ___ ___ __ _| |_ ___ 3 // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \ 4 // \ V V / __/ (_| |\ V /| | (_| | || __/ 5 // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___| 6 // 7 // Copyright © 2016 - 2024 Weaviate B.V. All rights reserved. 8 // 9 // CONTACT: hello@weaviate.io 10 // 11 12 package lsmkv 13 14 import ( 15 "bytes" 16 "testing" 17 18 "github.com/stretchr/testify/require" 19 ) 20 21 func BenchmarkReplaceNodeKeyIndexAndWriteTo(b *testing.B) { 22 // targetBuf := bytes.NewBuffer(make([]byte, 32*1024*1024)) // large enough to avoid growths during running 23 targetBuf := bytes.NewBuffer(nil) // large enough to avoid growths during running 24 25 node := segmentReplaceNode{ 26 tombstone: true, 27 value: []byte("foo bar"), 28 primaryKey: []byte("foo bar"), 29 secondaryIndexCount: 1, 30 secondaryKeys: [][]byte{[]byte("foo bar")}, 31 offset: 27, 32 } 33 34 b.ReportAllocs() 35 36 for i := 0; i < b.N; i++ { 37 _, err := node.KeyIndexAndWriteTo(targetBuf) 38 require.Nil(b, err) 39 } 40 } 41 42 func BenchmarkCollectionNodeKeyIndexAndWriteTo(b *testing.B) { 43 targetBuf := bytes.NewBuffer(make([]byte, 32*1024*1024)) // large enough to avoid growths during running 44 45 node := segmentCollectionNode{ 46 primaryKey: []byte("foo bar"), 47 offset: 27, 48 values: []value{ 49 { 50 value: []byte("my-value"), 51 tombstone: true, 52 }, 53 { 54 value: []byte("my-value"), 55 tombstone: true, 56 }, 57 }, 58 } 59 60 b.ReportAllocs() 61 62 for i := 0; i < b.N; i++ { 63 node.KeyIndexAndWriteTo(targetBuf) 64 } 65 }