@@ -7,17 +7,17 @@ import (
77)
88
99type Users struct {
10- UID uint `json:"uid,select(article)"` //select中表示选中的场景(该字段将会使用到的场景)
11- Avatar string `json:"avatar,select(article)"` //和上面一样此字段在article接口时才会解析该字段
10+ UID uint `json:"uid,select(article),omit(article) "` //select中表示选中的场景(该字段将会使用到的场景)
11+ Avatar string `json:"avatar,select(article),omit(article) "` //和上面一样此字段在article接口时才会解析该字段
1212
1313 Nickname string `json:"nickname,select(article|profile)"` //"|"表示有多个场景都需要这个字段 article接口需要 profile接口也需要
1414
15- Sex int `json:"sex,select(profile)"` //该字段是仅仅profile才使用
16- VipEndTime time.Time `json:"vip_end_time,select(profile)"` //同上
17- Price string `json:"price,select(profile)"` //同上
15+ Sex int `json:"sex,select(profile)"` //该字段是仅仅profile才使用
16+ VipEndTime time.Time `json:"vip_end_time,select(profile),omit(article) "` //同上
17+ Price string `json:"price,select(profile)"` //同上
1818
19- Hobby string `json:"hobby,omitempty,select($any)"` //任何场景下为空忽略
20- Lang []LangAge `json:"lang,omitempty,select($any)"` //任何场景下为空忽略
19+ Hobby string `json:"hobby,omitempty,select($any)"` //任何场景下为空忽略
20+ Lang []LangAge `json:"lang,omitempty,select($any),omit(article)"` //任何场景下为空忽略
2121}
2222
2323type LangAge struct {
@@ -48,29 +48,42 @@ func newUsers() Users {
4848
4949var str string
5050
51- func BenchmarkUserPointer (b * testing.B ) {
51+ func BenchmarkOmitPointerWithCache (b * testing.B ) {
5252 user := newUsers ()
53+ filter .EnableCache (true )
5354 for i := 0 ; i < b .N ; i ++ {
54- _ = filter .SelectMarshal ("article" , & user )
55+ _ = filter .Omit ("article" , & user )
5556 }
5657}
5758
58- func BenchmarkUserPointerWithCache (b * testing.B ) {
59+ func BenchmarkSelectPointerWithCache (b * testing.B ) {
5960 user := newUsers ()
61+ filter .EnableCache (true )
6062 for i := 0 ; i < b .N ; i ++ {
6163 _ = filter .Select ("article" , & user )
6264 }
6365}
6466
65- func BenchmarkUserVal (b * testing.B ) {
67+ func BenchmarkOmitVal (b * testing.B ) {
6668 user := newUsers ()
69+ filter .EnableCache (false )
6770 for i := 0 ; i < b .N ; i ++ {
68- _ = filter .SelectMarshal ("article" , user )
71+ _ = filter .Omit ("article" , user )
6972 }
7073}
71- func BenchmarkUserValWithCache (b * testing.B ) {
74+ func BenchmarkSelectVal (b * testing.B ) {
7275 user := newUsers ()
76+ filter .EnableCache (false )
7377 for i := 0 ; i < b .N ; i ++ {
7478 _ = filter .Select ("article" , user )
7579 }
7680}
81+
82+ func BenchmarkAll (b * testing.B ) {
83+ for i := 0 ; i < b .N ; i ++ {
84+ b .Run ("BenchmarkOmitPointerWithCache" , BenchmarkOmitPointerWithCache )
85+ b .Run ("BenchmarkOmitVal" , BenchmarkOmitVal )
86+ b .Run ("BenchmarkSelectPointerWithCache" , BenchmarkSelectPointerWithCache )
87+ b .Run ("BenchmarkSelectVal" , BenchmarkSelectVal )
88+ }
89+ }
0 commit comments