代码拉取完成,页面将自动刷新
package kk_x
import (
"sync"
"testing"
"time"
)
type Hub struct {
clientPool sync.Pool
}
type Client struct {
Username string `gorm:"column:username;type:varchar(100);not null;unique" json:"username"`
RealName string `gorm:"column:real_name;type:varchar(100);default:'';not null" json:"real_name"`
Password string `gorm:"column:password;type:varchar(100);not null" json:"password"`
TelNum string `gorm:"column:tel_num;type:varchar(100);default:'';not null" json:"tel_num"`
Notes string `gorm:"column:notes;type:varchar(255);default:'';not null" json:"notes"`
Gender int32 `gorm:"column:gender;type:smallint;default:0;not null" json:"gender"` //0 女 1 男
IdCard string `gorm:"column:id_card;type:varchar(100);default:'';not null" json:"id_card"`
RealNameAuthenticationWay int32 `gorm:"column:real_name_authentication_way;type:smallint;default:0;not null" json:"real_name_authentication_way"`
Height float32 `gorm:"column:height;type:numeric(5,2);default:0.0;not null" json:"height"` // 身高
Weight float32 `gorm:"column:weight;type:numeric(5,2);default:0.0;not null" json:"weight"` // 体重
Nickname string `gorm:"column:nickname;type:varchar(100);default:'';not null" json:"nickname"` // 昵称
Birthday time.Time `gorm:"column:birthday;type:date;not null" json:"birthday"` // 生日
Labels string `gorm:"column:labels;type:varchar(500);default:'';not null" json:"labels"` // 个人标签
Introduction string `gorm:"column:introduction;type:varchar(500);default:'';not null" json:"introduction"` // 简介
Avatar string `gorm:"column:avatar;type:varchar(500);default:'';not null" json:"avatar"` // 头像
}
func NewHub() *Hub {
return &Hub{
clientPool: sync.Pool{
New: func() any {
return &Client{}
},
},
}
}
func (h *Hub) GetClient() *Client {
return h.clientPool.Get().(*Client)
}
func (h *Hub) PutClient(c *Client) {
h.clientPool.Put(c)
}
//func TestName(t *testing.T) {
// h := NewHub()
// for i := 0; i < 10; i++ {
// c1 := h.GetClient()
// log.Println(c1)
// h.PutClient(c1)
// }
//}
func Benchmark_Add(b *testing.B) {
h := NewHub()
for i := 0; i < b.N; i++ {
c1 := h.GetClient()
c1.Username = "username"
//log.Println(c1)
h.PutClient(c1)
}
}
func Benchmark_Add2(b *testing.B) {
for i := 0; i < b.N; i++ {
c1 := &Client{}
c1.Username = "username"
_ = c1
}
}
//go test -bench=. -benchmem sync_test.go
//cruvie@CruvieMac sync_t % go test -bench=. -benchmem sync_test.go
//goos: darwin
//goarch: arm64
//Benchmark_Add-8 147627990 7.897 ns/op 0 B/op 0 allocs/op
//Benchmark_Add2-8 1000000000 0.2918 ns/op 0 B/op 0 allocs/op
//PASS
//ok command-line-arguments 2.470s
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。