github.com/sttk/sabi@v0.5.0/benchmark/dax_src/benchmark_dax_src_test.go (about)

     1  package sabi_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/sttk/sabi"
     7  )
     8  
     9  type FooDaxConn struct{}
    10  
    11  func (conn FooDaxConn) Commit() sabi.Err { return sabi.Ok() }
    12  func (conn FooDaxConn) Rollback()        {}
    13  func (conn FooDaxConn) Close()           {}
    14  
    15  type FooDaxSrc struct{}
    16  
    17  func (ds FooDaxSrc) CreateDaxConn() (sabi.DaxConn, sabi.Err) {
    18  	return FooDaxConn{}, sabi.Ok()
    19  }
    20  func (ds FooDaxSrc) SetUp() sabi.Err { return sabi.Ok() }
    21  func (ds FooDaxSrc) End()            {}
    22  
    23  func BenchmarkDaxSrc_AddGlobalDaxSrc(b *testing.B) {
    24  	b.StartTimer()
    25  	for i := 0; i < b.N; i++ {
    26  		sabi.AddGlobalDaxSrc("foo", FooDaxSrc{})
    27  	}
    28  	b.StopTimer()
    29  }
    30  
    31  func BenchmarkDaxSrc_AddGlobalDaxSrcPointer(b *testing.B) {
    32  	b.StartTimer()
    33  	for i := 0; i < b.N; i++ {
    34  		sabi.AddGlobalDaxSrc("foo", &FooDaxSrc{})
    35  	}
    36  	b.StopTimer()
    37  }
    38  
    39  func NewFooDaxSrc() FooDaxSrc {
    40  	return FooDaxSrc{}
    41  }
    42  
    43  func BenchmarkDaxSrc_AddGlobalDaxSrc_withNewFunction(b *testing.B) {
    44  	b.StartTimer()
    45  	for i := 0; i < b.N; i++ {
    46  		sabi.AddGlobalDaxSrc("foo", NewFooDaxSrc())
    47  	}
    48  	b.StopTimer()
    49  }
    50  
    51  func BenchmarkDaxSrc_StartUpGlobalDaxSrcs(b *testing.B) {
    52  	sabi.AddGlobalDaxSrc("foo", FooDaxSrc{})
    53  	b.StartTimer()
    54  	for i := 0; i < b.N; i++ {
    55  		sabi.StartUpGlobalDaxSrcs()
    56  	}
    57  	b.StopTimer()
    58  }