github.com/puellanivis/breton@v0.2.16/lib/metrics/metrics_test.go (about)

     1  package metrics
     2  
     3  import (
     4  	"sync"
     5  	"testing"
     6  )
     7  
     8  var (
     9  	cnt = Counter("counter", "test counter")
    10  )
    11  
    12  func BenchmarkPrometheusCounterInc(b *testing.B) {
    13  	for i := 0; i < b.N; i++ {
    14  		cnt.c.Inc()
    15  	}
    16  }
    17  
    18  func BenchmarkPrometheusCounterIncWithHeavyContention(b *testing.B) {
    19  	var wg sync.WaitGroup
    20  
    21  	n := 4
    22  
    23  	wg.Add(n)
    24  
    25  	for j := 0; j < n; j++ {
    26  		go func() {
    27  			defer wg.Done()
    28  
    29  			for i := 0; i < b.N; i++ {
    30  				cnt.c.Inc()
    31  			}
    32  		}()
    33  	}
    34  
    35  	wg.Wait()
    36  }