github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/pkg/sink/codec/simple/marshaller_bench_test.go (about) 1 // Copyright 2024 PingCAP, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package simple 15 16 import ( 17 "testing" 18 19 "github.com/pingcap/errors" 20 "github.com/pingcap/tiflow/cdc/model" 21 "github.com/pingcap/tiflow/pkg/config" 22 "github.com/pingcap/tiflow/pkg/sink/codec/common" 23 "github.com/pingcap/tiflow/pkg/sink/codec/utils" 24 ) 25 26 var event *model.RowChangedEvent 27 28 func eventGenerator() *model.RowChangedEvent { 29 if event == nil { 30 t := &testing.T{} 31 _, insertEvent, _, _ := utils.NewLargeEvent4Test(t, config.GetDefaultReplicaConfig()) 32 event = insertEvent 33 } 34 return event 35 } 36 37 // Note(dongmen): Below is the result of running the benchmark at 2024-4-22. 38 // goos: linux 39 // goarch: amd64 40 // pkg: github.com/pingcap/tiflow/pkg/sink/codec/simple 41 // cpu: Intel(R) Xeon(R) Gold 6240 CPU @ 2.60GHz 42 // BenchmarkMarshalRowChangedEvent-16 47527 29011 ns/op 8161 B/op 130 allocs/op 43 func BenchmarkMarshalRowChangedEvent(b *testing.B) { 44 codecConfig := common.NewConfig(config.ProtocolSimple) 45 avroMarshaller, err := newAvroMarshaller(codecConfig, string(avroSchemaBytes)) 46 if err != nil { 47 panic(err) 48 } 49 rowChangeEvent := eventGenerator() 50 if rowChangeEvent == nil { 51 panic(errors.New("event is nil")) 52 } 53 handleKeyOnly := false 54 claimCheckFileName := "" 55 56 b.ResetTimer() 57 for i := 0; i < b.N; i++ { 58 _, err := avroMarshaller.MarshalRowChangedEvent( 59 rowChangeEvent, 60 handleKeyOnly, 61 claimCheckFileName) 62 if err != nil { 63 panic(errors.Trace(err)) 64 } 65 } 66 }