mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-10 12:30:25 +08:00
优化基准测试
This commit is contained in:
@@ -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))
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user