github.com/gogf/gf@v1.16.9/container/gqueue/gqueue_z_bench_test.go (about) 1 // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/gogf/gf. 6 7 // go test *.go -bench=".*" -benchmem 8 9 package gqueue_test 10 11 import ( 12 "testing" 13 14 "github.com/gogf/gf/container/gqueue" 15 ) 16 17 var bn = 20000000 18 var length = 1000000 19 var qstatic = gqueue.New(length) 20 var qdynamic = gqueue.New() 21 var cany = make(chan interface{}, length) 22 23 func Benchmark_Gqueue_StaticPushAndPop(b *testing.B) { 24 b.N = bn 25 for i := 0; i < b.N; i++ { 26 qstatic.Push(i) 27 qstatic.Pop() 28 } 29 } 30 31 func Benchmark_Gqueue_DynamicPush(b *testing.B) { 32 b.N = bn 33 for i := 0; i < b.N; i++ { 34 qdynamic.Push(i) 35 } 36 } 37 38 func Benchmark_Gqueue_DynamicPop(b *testing.B) { 39 b.N = bn 40 for i := 0; i < b.N; i++ { 41 qdynamic.Pop() 42 } 43 } 44 45 func Benchmark_Channel_PushAndPop(b *testing.B) { 46 b.N = bn 47 for i := 0; i < b.N; i++ { 48 cany <- i 49 <-cany 50 } 51 }