internal/benchmarks/micro: add validator microbenchmarks
Change-Id: Ice768d90e650bf51d619b8cd5f5d51e6b00c53b6
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/216623
Reviewed-by: Joe Tsai <joetsai@google.com>
diff --git a/internal/benchmarks/micro/micro_test.go b/internal/benchmarks/micro/micro_test.go
index 20a6fea..097a326 100644
--- a/internal/benchmarks/micro/micro_test.go
+++ b/internal/benchmarks/micro/micro_test.go
@@ -11,7 +11,10 @@
import (
"testing"
+ "google.golang.org/protobuf/internal/impl"
"google.golang.org/protobuf/proto"
+ "google.golang.org/protobuf/reflect/protoregistry"
+ "google.golang.org/protobuf/runtime/protoiface"
"google.golang.org/protobuf/types/known/emptypb"
micropb "google.golang.org/protobuf/internal/testprotos/benchmarks/micro"
@@ -45,6 +48,19 @@
}
})
})
+ b.Run("Wire/Validate", func(b *testing.B) {
+ b.RunParallel(func(pb *testing.PB) {
+ mt := (&emptypb.Empty{}).ProtoReflect().Type()
+ opts := protoiface.UnmarshalOptions{
+ Resolver: protoregistry.GlobalTypes,
+ }
+ for pb.Next() {
+ if got, want := impl.Validate([]byte{}, mt, opts), impl.ValidationValidInitialized; got != want {
+ b.Fatalf("Validate = %v, want %v", got, want)
+ }
+ }
+ })
+ })
}
// BenchmarkRepeatedInt32 tests a message containing 500 non-packed repeated int32s.
@@ -83,6 +99,19 @@
}
})
})
+ b.Run("Wire/Validate", func(b *testing.B) {
+ b.RunParallel(func(pb *testing.PB) {
+ mt := (&testpb.TestAllTypes{}).ProtoReflect().Type()
+ opts := protoiface.UnmarshalOptions{
+ Resolver: protoregistry.GlobalTypes,
+ }
+ for pb.Next() {
+ if got, want := impl.Validate(w, mt, opts), impl.ValidationValidInitialized; got != want {
+ b.Fatalf("Validate = %v, want %v", got, want)
+ }
+ }
+ })
+ })
}
// BenchmarkRequired tests a message containing a required field.
@@ -131,4 +160,17 @@
}
})
})
+ b.Run("Wire/Validate", func(b *testing.B) {
+ b.RunParallel(func(pb *testing.PB) {
+ mt := (µpb.SixteenRequired{}).ProtoReflect().Type()
+ opts := protoiface.UnmarshalOptions{
+ Resolver: protoregistry.GlobalTypes,
+ }
+ for pb.Next() {
+ if got, want := impl.Validate(w, mt, opts), impl.ValidationValidInitialized; got != want {
+ b.Fatalf("Validate = %v, want %v", got, want)
+ }
+ }
+ })
+ })
}