优化基准测试

This commit is contained in:
刘祥超
2022-04-10 21:21:45 +08:00
parent 715e79c3e1
commit 065dda1dbf

View File

@@ -5,6 +5,7 @@ package setutils_test
import ( import (
setutils "github.com/TeaOSLab/EdgeNode/internal/utils/sets" setutils "github.com/TeaOSLab/EdgeNode/internal/utils/sets"
"github.com/iwind/TeaGo/assert" "github.com/iwind/TeaGo/assert"
"github.com/iwind/TeaGo/rands"
"testing" "testing"
) )
@@ -45,13 +46,17 @@ func TestFixedSet_Reset(t *testing.T) {
} }
func BenchmarkFixedSet_Has(b *testing.B) { func BenchmarkFixedSet_Has(b *testing.B) {
var count = 100_000 var count = 1_000_000
var set = setutils.NewFixedSet(count) var set = setutils.NewFixedSet(count)
for i := 0; i < count; i++ { for i := 0; i < count; i++ {
set.Push(i) set.Push(i)
} }
for i := 0; i < b.N; i++ { b.ResetTimer()
set.Has(i)
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
set.Has(rands.Int(0, 100_000))
} }
})
} }