diff --git a/g/container/gqueue/gqueue_test.go b/g/container/gqueue/gqueue_test.go index f177ce62e..173572dcd 100644 --- a/g/container/gqueue/gqueue_test.go +++ b/g/container/gqueue/gqueue_test.go @@ -14,7 +14,8 @@ import ( ) var length = 10000000 -var q = gqueue.New(length) +var q = gqueue.New(length) +var c = make(chan int, length) func BenchmarkGqueueNew1000W(b *testing.B) { for i := 0; i < b.N; i++ { @@ -22,6 +23,12 @@ func BenchmarkGqueueNew1000W(b *testing.B) { } } +func BenchmarkChannelNew1000W(b *testing.B) { + for i := 0; i < b.N; i++ { + c = make(chan int, length) + } +} + func BenchmarkGqueuePush(b *testing.B) { for i := 0; i < b.N; i++ { q.PushBack(i) @@ -35,3 +42,10 @@ func BenchmarkGqueuePushAndPop(b *testing.B) { } } +func BenchmarkChannelPushAndPop(b *testing.B) { + for i := 0; i < b.N; i++ { + c <- i + <- c + } +} + diff --git a/geg/container/gqueue.go b/geg/container/gqueue.go deleted file mode 100644 index f85a62ed3..000000000 --- a/geg/container/gqueue.go +++ /dev/null @@ -1,32 +0,0 @@ -package main - -import ( - "fmt" - "gitee.com/johng/gf/g/os/gtime" - "gitee.com/johng/gf/g/container/gqueue" - "time" -) - -func main() { - t := gtime.Microsecond() - q := gqueue.NewInterfaceQueue() - fmt.Println("queue creation costs(μs):", gtime.Microsecond() - t) - - // 每隔2秒异步打印出当前队列的大小 - gtime.SetInterval(2*time.Second, func() bool { - fmt.Println("queue size:", q.Size()) - return true - }) - - // push10条数据 - for i := 0; i < 10; i++ { - q.Push(i) - fmt.Println("push:", i) - } - - // 每隔1秒pop1条数据 - for { - time.Sleep(time.Second) - fmt.Println(" pop:", q.Pop()) - } -}