X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=codec%2Fbench_test.go;fp=codec%2Fbench_test.go;h=6889fa7ff56023c53aab0524f2b243dfabd9d5ea;hb=94620e85f0bdbb054af07ce3670fadc1f76cfdf0;hp=0000000000000000000000000000000000000000;hpb=280b1c6c83b676ef4e592f4ecf60cb5b54b6a753;p=govpp.git diff --git a/codec/bench_test.go b/codec/bench_test.go new file mode 100644 index 0000000..6889fa7 --- /dev/null +++ b/codec/bench_test.go @@ -0,0 +1,90 @@ +// Copyright (c) 2020 Cisco and/or its affiliates. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package codec_test + +import ( + "fmt" + "testing" + + "git.fd.io/govpp.git/codec" +) + +var Data []byte + +func BenchmarkEncode(b *testing.B) { + m := NewTestAllMsg() + + var err error + var data []byte + + for i := 0; i < b.N; i++ { + c := codec.MsgCodec{} + data, err = c.EncodeMsg(m, 100) + if err != nil { + b.Fatalf("expected nil error, got: %v", err) + } + } + Data = data +} + +func BenchmarkEncodeStruc(b *testing.B) { + m := NewTestAllMsg() + c := codec.OldCodec{} + + var err error + var data []byte + + b.ResetTimer() + for i := 0; i < b.N; i++ { + data, err = c.Marshal(m) + if err != nil { + b.Fatalf("expected nil error, got: %v", err) + } + } + Data = data + fmt.Printf("DATA(%d): % 0X\n", len(Data), Data) +} + +/*func BenchmarkEncodeNew(b *testing.B) { + m := NewTestAllMsg() + + var err error + var data []byte + + for i := 0; i < b.N; i++ { + c := CodecNew{} + data, err = c.Marshal(m) + if err != nil { + b.Fatalf("expected nil error, got: %v", err) + } + } + Data = data +}*/ +func BenchmarkEncodeHard(b *testing.B) { + m := NewTestAllMsg() + + var err error + var data []byte + + b.ResetTimer() + for i := 0; i < b.N; i++ { + data, err = m.Marshal(nil) + if err != nil { + b.Fatalf("expected nil error, got: %v", err) + } + } + Data = data + fmt.Printf("DATA(%d): % 0X\n", len(Data), Data) +}