github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/storage/enginepb/decode_test.go (about) 1 // Copyright 2018 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package enginepb_test 12 13 import ( 14 "encoding/binary" 15 "testing" 16 17 "github.com/cockroachdb/cockroach/pkg/roachpb" 18 "github.com/cockroachdb/cockroach/pkg/storage" 19 "github.com/cockroachdb/cockroach/pkg/storage/enginepb" 20 "github.com/cockroachdb/cockroach/pkg/util/hlc" 21 ) 22 23 func BenchmarkScanDecodeKeyValue(b *testing.B) { 24 key := roachpb.Key("blah blah blah") 25 ts := hlc.Timestamp{WallTime: int64(1000000)} 26 value := []byte("foo foo foo") 27 rep := make([]byte, 8) 28 keyBytes := storage.EncodeKey(storage.MVCCKey{Key: key, Timestamp: ts}) 29 binary.LittleEndian.PutUint64(rep, uint64(len(keyBytes)<<32)|uint64(len(value))) 30 rep = append(rep, keyBytes...) 31 rep = append(rep, value...) 32 b.Run("getTs=true", func(b *testing.B) { 33 for i := 0; i < b.N; i++ { 34 var err error 35 _, _, _, _, err = enginepb.ScanDecodeKeyValue(rep) 36 if err != nil { 37 b.Fatal(err) 38 } 39 } 40 }) 41 b.Run("getTs=false", func(b *testing.B) { 42 for i := 0; i < b.N; i++ { 43 var err error 44 _, _, _, err = enginepb.ScanDecodeKeyValueNoTS(rep) 45 if err != nil { 46 b.Fatal(err) 47 } 48 } 49 }) 50 }