test: 增加 buffer.Unbounded 测试用例

This commit is contained in:
kercylan98 2023-12-23 18:09:11 +08:00
parent 7111350022
commit cc5274ce62
2 changed files with 22 additions and 22 deletions

View File

@ -6,29 +6,12 @@ import (
)
func BenchmarkUnboundedBuffer(b *testing.B) {
ub := buffer.NewUnboundedN[int]()
ub := buffer.NewUnbounded[int]()
b.Run("Put", func(b *testing.B) {
for i := 0; i < b.N; i++ {
ub.Put(i)
}
})
b.Run("Load", func(b *testing.B) {
for i := 0; i < b.N; i++ {
ub.Load()
}
})
// 先填充数据以防止 Get 被阻塞
for i := 0; i < b.N; i++ {
ub.Put(i)
}
b.Run("Get", func(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
ub.Put(i)
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
ub.Put(1)
<-ub.Get()
ub.Load()
}

View File

@ -0,0 +1,17 @@
package buffer_test
import (
"fmt"
"github.com/kercylan98/minotaur/utils/buffer"
"testing"
)
func TestUnbounded_Get(t *testing.T) {
ub := buffer.NewUnbounded[int]()
for i := 0; i < 100; i++ {
ub.Put(i + 1)
fmt.Println(<-ub.Get())
//<-ub.Get()
ub.Load()
}
}