完善gqueue基准测试

This commit is contained in:
John
2018-02-28 14:16:24 +08:00
parent 07d4d94111
commit bc47c68e9f
2 changed files with 15 additions and 33 deletions

View File

@ -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
}
}

View File

@ -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())
}
}