github.com/gogf/gf/v2@v2.7.4/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/v2/container/gqueue" 15 ) 16 17 var bn = 20000000 18 19 var length = 1000000 20 21 var qstatic = gqueue.New(length) 22 23 var qdynamic = gqueue.New() 24 25 var cany = make(chan interface{}, length) 26 27 func Benchmark_Gqueue_StaticPushAndPop(b *testing.B) { 28 b.N = bn 29 for i := 0; i < b.N; i++ { 30 qstatic.Push(i) 31 qstatic.Pop() 32 } 33 } 34 35 func Benchmark_Gqueue_DynamicPush(b *testing.B) { 36 b.N = bn 37 for i := 0; i < b.N; i++ { 38 qdynamic.Push(i) 39 } 40 } 41 42 func Benchmark_Gqueue_DynamicPop(b *testing.B) { 43 b.N = bn 44 for i := 0; i < b.N; i++ { 45 qdynamic.Pop() 46 } 47 } 48 49 func Benchmark_Channel_PushAndPop(b *testing.B) { 50 b.N = bn 51 for i := 0; i < b.N; i++ { 52 cany <- i 53 <-cany 54 } 55 }