github.com/gogf/gf@v1.16.9/container/gring/gring_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=".*"
     8  
     9  package gring_test
    10  
    11  import (
    12  	"testing"
    13  
    14  	"github.com/gogf/gf/container/gring"
    15  )
    16  
    17  var length = 10000
    18  var ringObject = gring.New(length, true)
    19  
    20  func BenchmarkRing_Put(b *testing.B) {
    21  	b.RunParallel(func(pb *testing.PB) {
    22  		i := 0
    23  		for pb.Next() {
    24  			ringObject.Put(i)
    25  			i++
    26  		}
    27  	})
    28  }
    29  
    30  func BenchmarkRing_Next(b *testing.B) {
    31  	b.RunParallel(func(pb *testing.PB) {
    32  		i := 0
    33  		for pb.Next() {
    34  			ringObject.Next()
    35  			i++
    36  		}
    37  	})
    38  }
    39  
    40  func BenchmarkRing_Set(b *testing.B) {
    41  	b.RunParallel(func(pb *testing.PB) {
    42  		i := 0
    43  		for pb.Next() {
    44  			ringObject.Set(i)
    45  			i++
    46  		}
    47  	})
    48  }
    49  
    50  func BenchmarkRing_Len(b *testing.B) {
    51  	b.RunParallel(func(pb *testing.PB) {
    52  		i := 0
    53  		for pb.Next() {
    54  			ringObject.Len()
    55  			i++
    56  		}
    57  	})
    58  }
    59  
    60  func BenchmarkRing_Cap(b *testing.B) {
    61  	b.RunParallel(func(pb *testing.PB) {
    62  		i := 0
    63  		for pb.Next() {
    64  			ringObject.Cap()
    65  			i++
    66  		}
    67  	})
    68  }