gf/g/container/gqueue/gqueue_bench_test.go

51 lines
1.1 KiB
Go
Raw Normal View History

// Copyright 2017 gf Author(https://github.com/gogf/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://github.com/gogf/gf.
// go test *.go -bench=".*" -benchmem
package gqueue_test
import (
"testing"
"github.com/gogf/gf/g/container/gqueue"
)
2018-11-18 22:22:44 +08:00
var bn = 20000000
var length = 1000000
var qstatic = gqueue.New(length)
var qdynamic = gqueue.New()
var cany = make(chan interface{}, length)
2018-11-18 22:22:44 +08:00
func Benchmark_Gqueue_StaticPushAndPop(b *testing.B) {
b.N = bn
for i := 0; i < b.N; i++ {
qstatic.Push(i)
qstatic.Pop()
}
}
2018-11-18 22:22:44 +08:00
func Benchmark_Gqueue_DynamicPush(b *testing.B) {
b.N = bn
2018-02-28 14:16:24 +08:00
for i := 0; i < b.N; i++ {
qdynamic.Push(i)
2018-02-28 14:16:24 +08:00
}
}
2018-11-18 22:22:44 +08:00
func Benchmark_Gqueue_DynamicPop(b *testing.B) {
b.N = bn
for i := 0; i < b.N; i++ {
2018-11-18 22:22:44 +08:00
qdynamic.Pop()
}
}
2018-11-18 22:22:44 +08:00
func Benchmark_Channel_PushAndPop(b *testing.B) {
b.N = bn
for i := 0; i < b.N; i++ {
2018-11-18 22:22:44 +08:00
cany <- i
<- cany
2018-02-28 14:16:24 +08:00
}
}