github.com/brownsys/tracing-framework-go@v0.0.0-20161210174012-0542a62412fe/other/internal/gls/shim_bench_test.go (about)

     1  // +build !goid
     2  
     3  package gls
     4  
     5  import (
     6  	"runtime"
     7  	"sync"
     8  	"testing"
     9  )
    10  
    11  func BenchmarkSpawnShim(b *testing.B) {
    12  	var wg sync.WaitGroup
    13  	wg.Add(b.N)
    14  	b.ResetTimer()
    15  	for i := 0; i < b.N; i++ {
    16  		Go(func() { wg.Done() })
    17  	}
    18  	wg.Wait()
    19  }
    20  
    21  func BenchmarkPointerResolution(b *testing.B) {
    22  	var wg sync.WaitGroup
    23  	wg.Add(1)
    24  	f := func() {
    25  		b.ResetTimer()
    26  		for i := 0; i < b.N; i++ {
    27  			getPtr()
    28  		}
    29  		b.StopTimer()
    30  		wg.Done()
    31  	}
    32  	Go(f)
    33  	wg.Wait()
    34  }
    35  
    36  func BenchmarkPointerResolutionContention(b *testing.B) {
    37  	var wg sync.WaitGroup
    38  
    39  	f := func() {
    40  		for i := 0; i < b.N; i++ {
    41  			getPtr()
    42  		}
    43  		wg.Done()
    44  	}
    45  
    46  	b.ResetTimer()
    47  	for i := 0; i < runtime.NumCPU(); i++ {
    48  		wg.Add(1)
    49  		Go(f)
    50  	}
    51  	wg.Wait()
    52  }
    53  
    54  func BenchmarkPutShim(b *testing.B) {
    55  	nroutines := runtime.NumCPU() * 4
    56  	var wg sync.WaitGroup
    57  	wg.Add(nroutines)
    58  	b.ResetTimer()
    59  	for i := 0; i < nroutines; i++ {
    60  		Go(func() {
    61  			for i := 0; i < b.N; i++ {
    62  				Put(1, 1)
    63  			}
    64  			wg.Done()
    65  		})
    66  	}
    67  	wg.Wait()
    68  }
    69  
    70  func BenchmarkGetShim(b *testing.B) {
    71  	nroutines := runtime.NumCPU() * 4
    72  	var wg sync.WaitGroup
    73  	wg.Add(nroutines)
    74  	b.ResetTimer()
    75  	for i := 0; i < nroutines; i++ {
    76  		Go(func() {
    77  			for i := 0; i < b.N; i++ {
    78  				Get(1)
    79  			}
    80  			wg.Done()
    81  		})
    82  	}
    83  	wg.Wait()
    84  }
    85  
    86  func BenchmarkDeleteShim(b *testing.B) {
    87  	nroutines := runtime.NumCPU() * 4
    88  	var wg sync.WaitGroup
    89  	wg.Add(nroutines)
    90  	b.ResetTimer()
    91  	for i := 0; i < nroutines; i++ {
    92  		Go(func() {
    93  			for i := 0; i < b.N; i++ {
    94  				Delete(1)
    95  			}
    96  			wg.Done()
    97  		})
    98  	}
    99  	wg.Wait()
   100  }