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