2021-01-17 21:46:25 +08:00
|
|
|
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
2020-11-08 15:44:04 +08:00
|
|
|
//
|
|
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
|
|
// If a copy of the MIT was not distributed with this file,
|
|
|
|
// You can obtain one at https://github.com/gogf/gf.
|
|
|
|
|
|
|
|
package structs_test
|
|
|
|
|
|
|
|
import (
|
2021-10-11 21:41:56 +08:00
|
|
|
"github.com/gogf/gf/v2/internal/structs"
|
2020-11-08 15:44:04 +08:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
type User struct {
|
|
|
|
Id int
|
|
|
|
Name string `params:"name"`
|
|
|
|
Pass string `my-tag1:"pass1" my-tag2:"pass2" params:"pass"`
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
user = new(User)
|
|
|
|
userNilPointer *User
|
|
|
|
)
|
|
|
|
|
|
|
|
func Benchmark_TagFields(b *testing.B) {
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
structs.TagFields(user, []string{"params", "my-tag1"})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Benchmark_TagFields_NilPointer(b *testing.B) {
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
structs.TagFields(&userNilPointer, []string{"params", "my-tag1"})
|
|
|
|
}
|
|
|
|
}
|