mirror of
https://github.com/valyala/fasthttp.git
synced 2026-06-14 15:56:44 +03:00
f196617f55
gofmt -w -r "interface{} -> any" -l .
41 lines
689 B
Go
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)
|
|
}
|
|
}
|