package starmap import ( "fmt" "sync/atomic" "testing" "time" ) func Test_Circle_Speed(t *testing.T) { buf := StarStack{} count := uint64(0) for i := 1; i <= 10; i++ { go func() { for { buf.Push('a') } }() } for i := 1; i <= 10; i++ { go func() { for { _, err := buf.Pop() if err == nil { atomic.AddUint64(&count, 1) } } }() } time.Sleep(time.Second * 10) fmt.Println(count) } func Test_Chan_Circle_Speed(t *testing.T) { buf := StarChanStack{} count := uint64(0) for i := 1; i <= 10; i++ { go func() { for { err := buf.Push('a') if err != nil { fmt.Println("finished write") break } } }() } for i := 1; i <= 10; i++ { go func() { for { _, err := buf.Pop() if err == nil { atomic.AddUint64(&count, 1) } else { fmt.Println("finished read") break } } }() } time.Sleep(time.Second * 10) fmt.Println(count) buf.Close() time.Sleep(time.Second * 3) }