2 Star 3 Fork 10

王布衣 / engine

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
scoreboard.go 1.17 KB
一键复制 编辑 原始数据 按行查看 历史
王布衣 提交于 2024-01-19 07:10 . 调整记分牌String方法
package cache
import (
"fmt"
"sync"
"time"
)
// ScoreBoard 记分牌
type ScoreBoard struct {
m sync.Mutex
Name string `name:"name"` // 名称
Kind Kind `name:"kind"` // 类型
Count int `name:"count"` // 总数
Max time.Duration `name:"max"` // 最大值
Min time.Duration `name:"min"` // 最小值
CrossTime time.Duration `name:"cross_time"` // 总耗时
Speed float64 `name:"speed"` // 速度
}
func (this *ScoreBoard) From(adapter DataAdapter) {
this.Name = adapter.Name()
this.Kind = adapter.Kind()
}
func (this *ScoreBoard) Add(delta int, take time.Duration) {
this.m.Lock()
defer this.m.Unlock()
this.Count = this.Count + delta
this.CrossTime += take
if this.Min == 0 || this.Min > take {
this.Min = take
}
if this.Max == 0 || this.Max < take {
this.Max = take
}
this.Speed = float64(this.Count) / this.CrossTime.Seconds()
}
func (this *ScoreBoard) String() string {
s := fmt.Sprintf("name: %s, kind: %d, total: %d, crosstime: %s, max: %d, min: %d, speed: %f", this.Name, this.Kind, this.Count, this.CrossTime, this.Max, this.Min, this.Speed)
return s
}
1
https://gitee.com/quant1x/engine.git
git@gitee.com:quant1x/engine.git
quant1x
engine
engine
v1.8.4

搜索帮助