github.com/wangyougui/gf/v2@v2.6.5/os/gstructs/gstructs_z_bench_test.go (about) 1 // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/wangyougui/gf. 6 7 package gstructs_test 8 9 import ( 10 "reflect" 11 "testing" 12 13 "github.com/wangyougui/gf/v2/os/gstructs" 14 ) 15 16 type User struct { 17 Id int 18 Name string `params:"name"` 19 Pass string `my-tag1:"pass1" my-tag2:"pass2" params:"pass"` 20 } 21 22 var ( 23 user = new(User) 24 userNilPointer *User 25 ) 26 27 func Benchmark_ReflectTypeOf(b *testing.B) { 28 for i := 0; i < b.N; i++ { 29 reflect.TypeOf(user).String() 30 } 31 } 32 33 func Benchmark_TagFields(b *testing.B) { 34 for i := 0; i < b.N; i++ { 35 gstructs.TagFields(user, []string{"params", "my-tag1"}) 36 } 37 } 38 39 func Benchmark_TagFields_NilPointer(b *testing.B) { 40 for i := 0; i < b.N; i++ { 41 gstructs.TagFields(&userNilPointer, []string{"params", "my-tag1"}) 42 } 43 }