init: v1.0.0

This commit is contained in:
yaole
2026-05-27 23:03:00 +08:00
commit 8d97f750eb
466 changed files with 80067 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
package internal
import (
"time"
)
const runningTime = 3 * time.Second
// SingleThreadTester 单线程测试f在固定时间内执行次数。返回执行函数f的次数和时间
func SingleThreadTester(f func()) (int, time.Duration) {
var start, end time.Time
var count int
timer := time.NewTimer(runningTime)
start = time.Now()
loop:
for {
select {
case <-timer.C:
end = time.Now()
break loop
default:
f()
count++
}
}
return count, end.Sub(start)
}
func Rate(count int, d time.Duration) float64 {
return float64(count) / d.Seconds()
}