github.com/MetalBlockchain/metalgo@v1.11.9/x/merkledb/bytes_pool_test.go (about)

     1  // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
     2  // See the file LICENSE for licensing terms.
     3  
     4  package merkledb
     5  
     6  import "testing"
     7  
     8  func Benchmark_BytesPool_Acquire(b *testing.B) {
     9  	s := newBytesPool(b.N)
    10  
    11  	b.ResetTimer()
    12  	for i := 0; i < b.N; i++ {
    13  		s.Acquire()
    14  	}
    15  }
    16  
    17  func Benchmark_BytesPool_Release(b *testing.B) {
    18  	s := newBytesPool(b.N)
    19  	for i := 0; i < b.N; i++ {
    20  		s.Acquire()
    21  	}
    22  
    23  	b.ResetTimer()
    24  	for i := 0; i < b.N; i++ {
    25  		s.Release(nil)
    26  	}
    27  }
    28  
    29  func Benchmark_BytesPool_TryAcquire_Success(b *testing.B) {
    30  	s := newBytesPool(b.N)
    31  
    32  	b.ResetTimer()
    33  	for i := 0; i < b.N; i++ {
    34  		s.TryAcquire()
    35  	}
    36  }
    37  
    38  func Benchmark_BytesPool_TryAcquire_Failure(b *testing.B) {
    39  	s := newBytesPool(1)
    40  	s.Acquire()
    41  
    42  	b.ResetTimer()
    43  	for i := 0; i < b.N; i++ {
    44  		s.TryAcquire()
    45  	}
    46  }