github.com/brownsys/tracing-framework-go@v0.0.0-20161210174012-0542a62412fe/other/internal/gls/goid_bench_test.go (about) 1 // +build goid 2 3 package gls 4 5 import ( 6 "runtime" 7 "sync" 8 "testing" 9 ) 10 11 func BenchmarkGoid(b *testing.B) { 12 for i := 0; i < b.N; i++ { 13 runtime.Goid() 14 } 15 } 16 17 func BenchmarkSpawnGoid(b *testing.B) { 18 var wg sync.WaitGroup 19 wg.Add(b.N) 20 b.ResetTimer() 21 for i := 0; i < b.N; i++ { 22 Go(func() { wg.Done() }) 23 } 24 wg.Wait() 25 } 26 27 func BenchmarkPutGoid(b *testing.B) { 28 nroutines := runtime.NumCPU() * 4 29 var wg sync.WaitGroup 30 wg.Add(nroutines) 31 b.ResetTimer() 32 for i := 0; i < nroutines; i++ { 33 Go(func() { 34 for i := 0; i < b.N; i++ { 35 Put(1, 1) 36 } 37 wg.Done() 38 }) 39 } 40 wg.Wait() 41 } 42 43 func BenchmarkGetGoid(b *testing.B) { 44 nroutines := runtime.NumCPU() * 4 45 var wg sync.WaitGroup 46 wg.Add(nroutines) 47 b.ResetTimer() 48 for i := 0; i < nroutines; i++ { 49 Go(func() { 50 for i := 0; i < b.N; i++ { 51 Get(1) 52 } 53 wg.Done() 54 }) 55 } 56 wg.Wait() 57 } 58 59 func BenchmarkDeleteGoid(b *testing.B) { 60 nroutines := runtime.NumCPU() * 4 61 var wg sync.WaitGroup 62 wg.Add(nroutines) 63 b.ResetTimer() 64 for i := 0; i < nroutines; i++ { 65 Go(func() { 66 for i := 0; i < b.N; i++ { 67 Delete(1) 68 } 69 wg.Done() 70 }) 71 } 72 wg.Wait() 73 }