2018-02-02 16:56:53 +08:00
|
|
|
// Copyright 2017 gf Author(https://gitee.com/johng/gf). All Rights Reserved.
|
|
|
|
|
//
|
|
|
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
|
|
|
// If a copy of the MIT was not distributed with this file,
|
|
|
|
|
// You can obtain one at https://gitee.com/johng/gf.
|
|
|
|
|
|
2018-09-15 16:40:13 +08:00
|
|
|
// go test *.go -bench=".*" -benchmem
|
2018-02-02 16:56:53 +08:00
|
|
|
|
|
|
|
|
package gqueue_test
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
"gitee.com/johng/gf/g/container/gqueue"
|
|
|
|
|
)
|
|
|
|
|
|
2018-09-15 16:40:13 +08:00
|
|
|
var length = 10000000
|
|
|
|
|
var qstatic = gqueue.New(length)
|
|
|
|
|
var qdynamic = gqueue.New()
|
|
|
|
|
var cany = make(chan interface{}, length)
|
|
|
|
|
var cint = make(chan int, length)
|
2018-02-02 16:56:53 +08:00
|
|
|
|
2018-09-15 16:40:13 +08:00
|
|
|
func Benchmark_GqueueStaticPushAndPop(b *testing.B) {
|
2018-02-02 16:56:53 +08:00
|
|
|
for i := 0; i < b.N; i++ {
|
2018-09-15 16:40:13 +08:00
|
|
|
qstatic.Push(i)
|
|
|
|
|
qstatic.Pop()
|
2018-02-02 16:56:53 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-16 10:51:02 +08:00
|
|
|
func Benchmark_GqueueDynamicPush(b *testing.B) {
|
2018-02-28 14:16:24 +08:00
|
|
|
for i := 0; i < b.N; i++ {
|
2018-09-15 16:40:13 +08:00
|
|
|
qdynamic.Push(i)
|
2018-02-28 14:16:24 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-15 16:40:13 +08:00
|
|
|
func Benchmark_ChannelInterfacePushAndPop(b *testing.B) {
|
2018-02-02 16:56:53 +08:00
|
|
|
for i := 0; i < b.N; i++ {
|
2018-09-15 16:40:13 +08:00
|
|
|
cany <- i
|
|
|
|
|
<- cany
|
2018-02-02 16:56:53 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-15 16:40:13 +08:00
|
|
|
func Benchmark_ChannelIntPushAndPop(b *testing.B) {
|
2018-02-02 16:56:53 +08:00
|
|
|
for i := 0; i < b.N; i++ {
|
2018-09-15 16:40:13 +08:00
|
|
|
cint <- i
|
|
|
|
|
<- cint
|
2018-02-28 14:16:24 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|