Fix structtags

This commit is contained in:
Fedor Korotkiy 2021-04-01 16:43:19 +03:00
parent e7909f0857
commit 688121f0bd
2 changed files with 16 additions and 6 deletions

View file

@ -2,15 +2,14 @@
Ускорьте функцию `Unpack()`.
Ваша функция должна работать быстрее, чем бейзлайн + 20%.
```
goos: linux
goarch: amd64
pkg: gitlab.com/slon/shad-go/structtags
cpu: Intel(R) Core(TM) i7-6600U CPU @ 2.60GHz
BenchmarkUnpacker/user-4 4269022 275.0 ns/op
BenchmarkUnpacker/user+good+order-4 732264 1481 ns/op
BenchmarkUnpacker/user-4 4158832 268.2 ns/op 0 B/op 0 allocs/op
BenchmarkUnpacker/good-4 1000000 1198 ns/op 220 B/op 6 allocs/op
BenchmarkUnpacker/order-4 1260784 1162 ns/op 282 B/op 6 allocs/op
PASS
```

View file

@ -138,16 +138,27 @@ func BenchmarkUnpacker(b *testing.B) {
order := &Order{}
b.Run("user", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = Unpack(userRequest, user)
}
})
b.Run("user+good+order", func(b *testing.B) {
b.Run("good", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = Unpack(userRequest, user)
_ = Unpack(goodRequest, good)
_ = Unpack(orderRequest, order)
}
})
b.Run("order", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = Unpack(orderRequest, order)
}
})
}