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