You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
984 B
Go
67 lines
984 B
Go
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)
|
|
}
|