github.com/zhongdalu/gf@v1.0.0/g/container/gpool/gpool_bench_test.go (about)

     1  // Copyright 2018 gf Author(https://github.com/zhongdalu/gf). 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/zhongdalu/gf.
     6  
     7  // go test *.go -bench=".*"
     8  
     9  package gpool_test
    10  
    11  import (
    12  	"github.com/zhongdalu/gf/g/container/gpool"
    13  	"sync"
    14  	"testing"
    15  )
    16  
    17  var pool = gpool.New(99999999, nil)
    18  var syncp = sync.Pool{}
    19  
    20  func BenchmarkGPoolPut(b *testing.B) {
    21  	for i := 0; i < b.N; i++ {
    22  		pool.Put(i)
    23  	}
    24  }
    25  
    26  func BenchmarkGPoolGet(b *testing.B) {
    27  	for i := 0; i < b.N; i++ {
    28  		pool.Get()
    29  	}
    30  }
    31  
    32  func BenchmarkSyncPoolPut(b *testing.B) {
    33  	for i := 0; i < b.N; i++ {
    34  		syncp.Put(i)
    35  	}
    36  }
    37  
    38  func BenchmarkGpoolGet(b *testing.B) {
    39  	for i := 0; i < b.N; i++ {
    40  		syncp.Get()
    41  	}
    42  }