github.com/wangyougui/gf/v2@v2.6.5/util/gmeta/gmeta_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 gmeta_test 8 9 import ( 10 "testing" 11 12 "github.com/wangyougui/gf/v2/util/gmeta" 13 ) 14 15 type A struct { 16 gmeta.Meta `tag:"123" orm:"456"` 17 Id int 18 Name string 19 } 20 21 var ( 22 a1 A 23 a2 *A 24 ) 25 26 func Benchmark_Data_Struct(b *testing.B) { 27 for i := 0; i < b.N; i++ { 28 gmeta.Data(a1) 29 } 30 } 31 32 func Benchmark_Data_Pointer1(b *testing.B) { 33 for i := 0; i < b.N; i++ { 34 gmeta.Data(a2) 35 } 36 } 37 38 func Benchmark_Data_Pointer2(b *testing.B) { 39 for i := 0; i < b.N; i++ { 40 gmeta.Data(&a2) 41 } 42 } 43 44 func Benchmark_Data_Get_Struct(b *testing.B) { 45 for i := 0; i < b.N; i++ { 46 gmeta.Get(a1, "tag") 47 } 48 } 49 50 func Benchmark_Data_Get_Pointer1(b *testing.B) { 51 for i := 0; i < b.N; i++ { 52 gmeta.Get(a2, "tag") 53 } 54 } 55 56 func Benchmark_Data_Get_Pointer2(b *testing.B) { 57 for i := 0; i < b.N; i++ { 58 gmeta.Get(&a2, "tag") 59 } 60 }