cosmos-sdk/codec/unknownproto/benchmarks_test.go
Amaury Martiny 55242a659c
Add ADR 031 BaseApp and codec infrastructure (#7519)
* Refactor RegisterQueryServices -> RegisterServices

* Cleaner proto files

* Fix tests

* Add MsgServer

* Fix lint

* Remove MsgServer from configurator for now

* Remove useless file

* Fix build

* typo

* Add router

* Fix test

* WIP

* Add router

* Remove test helper

* Add beginning of test

* Move test to simapp?

* ServiceMsg implement sdk.Msg

* Add handler by MsgServiceRouter

* Correct signature

* Add full test

* use TxEncoder

* Update baseapp/msg_service_router.go

Co-authored-by: Aaron Craelius <aaron@regen.network>

* Push changes

* WIP on ServiceMsg unpacking

* Make TestMsgService test pass

* Fix tests

* Tidying up

* Tidying up

* Tidying up

* Add JSON test

* Add comments

* Tidying

* Lint

* Register MsgRequest interface

* Rename

* Fix tests

* RegisterCustomTypeURL

* Add changelog entries

* Put in features

* Update baseapp/msg_service_router.go

Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>

* Update baseapp/msg_service_router.go

Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>

* Update baseapp/msg_service_router.go

Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>

* Update baseapp/msg_service_router.go

Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>

* Update baseapp/msg_service_router.go

Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>

* Update baseapp/msg_service_router.go

Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>

* Update baseapp/msg_service_router.go

Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>

* Address review comments

* Address nit

* Fix lint

* Update codec/types/interface_registry.go

Co-authored-by: Marie Gauthier <marie.gauthier63@gmail.com>

* godoc

Co-authored-by: Aaron Craelius <aaronc@users.noreply.github.com>
Co-authored-by: Aaron Craelius <aaron@regen.network>
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
Co-authored-by: Marie Gauthier <marie.gauthier63@gmail.com>
2020-10-15 13:07:59 +00:00

114 lines
2.4 KiB
Go

package unknownproto_test
import (
"sync"
"testing"
"github.com/gogo/protobuf/proto"
"github.com/cosmos/cosmos-sdk/codec/unknownproto"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
)
var n1BBlob []byte
func init() {
n1B := &testdata.Nested1B{
Id: 1,
Age: 99,
Nested: &testdata.Nested2B{
Id: 2,
Route: "Wintery route",
Fee: 99,
Nested: &testdata.Nested3B{
Id: 3,
Name: "3A this one that one there those oens",
Age: 4588,
B4: []*testdata.Nested4B{
{
Id: 4,
Age: 88,
Name: "Nested4B",
},
},
},
},
}
var err error
n1BBlob, err = proto.Marshal(n1B)
if err != nil {
panic(err)
}
}
func BenchmarkRejectUnknownFields_serial(b *testing.B) {
benchmarkRejectUnknownFields(b, false)
}
func BenchmarkRejectUnknownFields_parallel(b *testing.B) {
benchmarkRejectUnknownFields(b, true)
}
func benchmarkRejectUnknownFields(b *testing.B, parallel bool) {
b.ReportAllocs()
if !parallel {
b.ResetTimer()
for i := 0; i < b.N; i++ {
n1A := new(testdata.Nested1A)
if err := unknownproto.RejectUnknownFieldsStrict(n1BBlob, n1A, unknownproto.DefaultAnyResolver{}); err == nil {
b.Fatal("expected an error")
}
b.SetBytes(int64(len(n1BBlob)))
}
} else {
var mu sync.Mutex
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
// To simulate the conditions of multiple transactions being processed in parallel.
n1A := new(testdata.Nested1A)
if err := unknownproto.RejectUnknownFieldsStrict(n1BBlob, n1A, unknownproto.DefaultAnyResolver{}); err == nil {
b.Fatal("expected an error")
}
mu.Lock()
b.SetBytes(int64(len(n1BBlob)))
mu.Unlock()
}
})
}
}
func BenchmarkProtoUnmarshal_serial(b *testing.B) {
benchmarkProtoUnmarshal(b, false)
}
func BenchmarkProtoUnmarshal_parallel(b *testing.B) {
benchmarkProtoUnmarshal(b, true)
}
func benchmarkProtoUnmarshal(b *testing.B, parallel bool) {
b.ReportAllocs()
if !parallel {
for i := 0; i < b.N; i++ {
n1A := new(testdata.Nested1A)
if err := proto.Unmarshal(n1BBlob, n1A); err == nil {
b.Fatal("expected an error")
}
b.SetBytes(int64(len(n1BBlob)))
}
} else {
var mu sync.Mutex
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
n1A := new(testdata.Nested1A)
if err := proto.Unmarshal(n1BBlob, n1A); err == nil {
b.Fatal("expected an error")
}
mu.Lock()
b.SetBytes(int64(len(n1BBlob)))
mu.Unlock()
}
})
}
}