2 Star 15 Fork 17

王布衣/engine

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
scoreboard.go 1.50 KB
一键复制 编辑 原始数据 按行查看 历史
王布衣 提交于 2025-03-02 19:08 +08:00 . 优化backtest功能, 去除冗余的操作
package cache
import (
"fmt"
"sync"
"time"
)
// ScoreBoard 记分牌, 线程安全
type ScoreBoard struct {
m sync.Mutex
AdapterMetric
}
// AdapterMetric 适配器性能指标
type AdapterMetric struct {
Name string `name:"name"` // 名称
Kind Kind `name:"kind"` // 类型
Count int `name:"count"` // 总数
Passed int `name:"passed"` // 通过检测数
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, pass ...bool) {
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()
passed := false
if len(pass) > 0 {
passed = pass[0]
}
if passed {
this.Passed++
}
}
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
}
func (this *ScoreBoard) Metric() AdapterMetric {
return this.AdapterMetric
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/quant1x/engine.git
git@gitee.com:quant1x/engine.git
quant1x
engine
engine
v1.9.10

搜索帮助