2 Star 7 Fork 11

王布衣/engine

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
scoreboard.go 1013 Bytes
一键复制 编辑 原始数据 按行查看 历史
王布衣 提交于 2023-11-01 08:31 . 调整记分牌的tag
package cache
import (
"fmt"
"sync"
"time"
)
// ScoreBoard 记分牌
type ScoreBoard struct {
m sync.Mutex
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) 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("kind: %d, total: %d, crosstime: %s, max: %d, min: %d, speed: %f", this.Kind, this.Count, this.CrossTime, this.Max, this.Min, this.Speed)
return s
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/quant1x/engine.git
git@gitee.com:quant1x/engine.git
quant1x
engine
engine
v0.7.6

搜索帮助