Files
fasthttp/stackless/func_timing_test.go
T
Oleksandr Redko f196617f55 chore: Use 'any' instead of 'interface{}' (#1666)
gofmt -w -r "interface{} -> any" -l .
2023-11-24 11:33:04 +01:00

41 lines
689 B
Go

package stackless
import (
"sync/atomic"
"testing"
)
func BenchmarkFuncOverhead(b *testing.B) {
var n uint64
f := NewFunc(func(ctx any) {
atomic.AddUint64(&n, *(ctx.(*uint64)))
})
b.RunParallel(func(pb *testing.PB) {
x := uint64(1)
for pb.Next() {
if !f(&x) {
b.Fatalf("f mustn't return false")
}
}
})
if n != uint64(b.N) {
b.Fatalf("unexpected n: %d. Expecting %d", n, b.N)
}
}
func BenchmarkFuncPure(b *testing.B) {
var n uint64
f := func(x *uint64) {
atomic.AddUint64(&n, *x)
}
b.RunParallel(func(pb *testing.PB) {
x := uint64(1)
for pb.Next() {
f(&x)
}
})
if n != uint64(b.N) {
b.Fatalf("unexpected n: %d. Expecting %d", n, b.N)
}
}