[fidl] Improve benchmark error handling
Report errors when possible. Simplify timer management.
Change-Id: I45406f38423e6353bb64c574ba2f69bdf1738efb
diff --git a/src/syscall/zx/fidl/fidl_test/encoding_new_test.go b/src/syscall/zx/fidl/fidl_test/encoding_new_test.go
index 33bebc3..79688c0 100644
--- a/src/syscall/zx/fidl/fidl_test/encoding_new_test.go
+++ b/src/syscall/zx/fidl/fidl_test/encoding_new_test.go
@@ -1049,14 +1049,13 @@
}
func benchmarkMarshal(b *testing.B, ex example) {
+ var respb [zx.ChannelMaxMessageBytes]byte
+ var resphd [zx.ChannelMaxMessageHandles]zx.HandleDisposition
+
b.Run(ex.name, func(b *testing.B) {
- b.StopTimer()
- var respb [zx.ChannelMaxMessageBytes]byte
- var resphd [zx.ChannelMaxMessageHandles]zx.HandleDisposition
- b.StartTimer()
for n := 0; n < b.N; n++ {
if _, _, err := Marshal(ex.input, respb[:], resphd[:]); err != nil {
- b.Fail()
+ b.Fatal(err)
}
}
})
@@ -1072,13 +1071,13 @@
}
func benchmarkUnmarshal(b *testing.B, ex example) {
+ var respb [zx.ChannelMaxMessageBytes]byte
+ var resphd [zx.ChannelMaxMessageHandles]zx.HandleDisposition
+
b.Run(ex.name, func(b *testing.B) {
- b.StopTimer()
- var respb [zx.ChannelMaxMessageBytes]byte
- var resphd [zx.ChannelMaxMessageHandles]zx.HandleDisposition
nb, nh, err := Marshal(ex.input, respb[:], resphd[:])
if err != nil {
- b.Fail()
+ b.Fatal(err)
}
var resphi [zx.ChannelMaxMessageHandles]zx.HandleInfo
for i := 0; i < nh; i++ {
@@ -1089,10 +1088,10 @@
}
}
output := makeDefault(reflect.TypeOf(ex.input))
- b.StartTimer()
+ b.ResetTimer()
for n := 0; n < b.N; n++ {
if _, _, err := Unmarshal(respb[:nb], resphi[:nh], output); err != nil {
- b.Fail()
+ b.Fatal(err)
}
}
})