This commit is contained in:
Andy Pan 2018-05-23 23:55:42 +08:00
parent 2e3a9a650e
commit ea5025d8ab
1 changed files with 19 additions and 19 deletions

View File

@ -73,7 +73,7 @@ func TestDefaultPool(t *testing.T) {
t.Logf("running workers number:%d", ants.Running())
mem := runtime.MemStats{}
runtime.ReadMemStats(&mem)
t.Logf("memory usage:%d", mem.TotalAlloc/MiB)
t.Logf("memory usage:%d MB", mem.TotalAlloc/MiB)
}
func TestNoPool(t *testing.T) {
@ -89,30 +89,30 @@ func TestNoPool(t *testing.T) {
wg.Wait()
mem := runtime.MemStats{}
runtime.ReadMemStats(&mem)
t.Logf("memory usage:%d", mem.TotalAlloc/MiB)
t.Logf("memory usage:%d MB", mem.TotalAlloc/MiB)
}
func TestAntsPoolWithFunc(t *testing.T) {
var wg sync.WaitGroup
p, _ := ants.NewPoolWithFunc(50000, func(i interface{}) error {
demoPoolFunc(i)
wg.Done()
return nil
})
for i := 0; i < n; i++ {
wg.Add(1)
p.Serve(n)
}
wg.Wait()
//func TestAntsPoolWithFunc(t *testing.T) {
// var wg sync.WaitGroup
// p, _ := ants.NewPoolWithFunc(50000, func(i interface{}) error {
// demoPoolFunc(i)
// wg.Done()
// return nil
// })
// for i := 0; i < n; i++ {
// wg.Add(1)
// p.Serve(n)
// }
// wg.Wait()
//t.Logf("pool capacity:%d", ants.Cap())
//t.Logf("free workers number:%d", ants.Free())
t.Logf("running workers number:%d", p.Running())
mem := runtime.MemStats{}
runtime.ReadMemStats(&mem)
t.Logf("memory usage:%d", mem.TotalAlloc/GiB)
}
// t.Logf("running workers number:%d", p.Running())
// mem := runtime.MemStats{}
// runtime.ReadMemStats(&mem)
// t.Logf("memory usage:%d", mem.TotalAlloc/GiB)
//}
// func TestNoPool(t *testing.T) {
// var wg sync.WaitGroup