github.com/alphadose/itogami@v0.4.1-0.20221016160904-c25d0a36bfe7/benchmarks/throughput_test.go (about) 1 package test 2 3 import ( 4 "sync" 5 "testing" 6 "time" 7 8 "github.com/alphadose/itogami" 9 ) 10 11 var wg1, wg2, wg3 sync.WaitGroup 12 13 const sleepDuration uint8 = 10 14 15 func antsFunc(args any) { 16 time.Sleep(time.Duration(args.(uint8)) * time.Millisecond) 17 wg2.Done() 18 } 19 20 func itoFunc(args uint8) { 21 time.Sleep(time.Duration(args) * time.Millisecond) 22 wg3.Done() 23 } 24 25 // func BenchmarkAntsPooWithFunc(b *testing.B) { 26 // p, _ := ants.NewPoolWithFunc(PoolSize, antsFunc, ants.WithExpiryDuration(DefaultExpiredTime)) 27 // defer p.Release() 28 29 // b.ResetTimer() 30 // b.StartTimer() 31 // for i := 0; i < b.N; i++ { 32 // wg2.Add(RunTimes) 33 // for j := 0; j < RunTimes; j++ { 34 // p.Invoke(sleepDuration) 35 // } 36 // wg2.Wait() 37 // } 38 // b.StopTimer() 39 // } 40 41 func BenchmarkItogamiPoolWithFunc(b *testing.B) { 42 p := itogami.NewPoolWithFunc(PoolSize, itoFunc) 43 44 b.ResetTimer() 45 b.StartTimer() 46 for i := 0; i < b.N; i++ { 47 wg3.Add(RunTimes) 48 for j := 0; j < RunTimes; j++ { 49 p.Invoke(sleepDuration) 50 } 51 wg3.Wait() 52 } 53 b.StopTimer() 54 }