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