github.com/wangyougui/gf/v2@v2.6.5/container/gpool/gpool_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 gpool_test
    10  
    11  import (
    12  	"sync"
    13  	"testing"
    14  	"time"
    15  
    16  	"github.com/wangyougui/gf/v2/container/gpool"
    17  )
    18  
    19  var pool = gpool.New(time.Hour, nil)
    20  
    21  var syncp = sync.Pool{}
    22  
    23  func BenchmarkGPoolPut(b *testing.B) {
    24  	for i := 0; i < b.N; i++ {
    25  		pool.Put(i)
    26  	}
    27  }
    28  
    29  func BenchmarkGPoolGet(b *testing.B) {
    30  	for i := 0; i < b.N; i++ {
    31  		pool.Get()
    32  	}
    33  }
    34  
    35  func BenchmarkSyncPoolPut(b *testing.B) {
    36  	for i := 0; i < b.N; i++ {
    37  		syncp.Put(i)
    38  	}
    39  }
    40  
    41  func BenchmarkSyncPoolGet(b *testing.B) {
    42  	for i := 0; i < b.N; i++ {
    43  		syncp.Get()
    44  	}
    45  }