TestAntsPoolWithFuncGenericGetWorkerFromCache is used to test getting worker from sync.Pool.
(t *testing.T)
| 212 | |
| 213 | // TestAntsPoolWithFuncGenericGetWorkerFromCache is used to test getting worker from sync.Pool. |
| 214 | func TestAntsPoolWithFuncGenericGetWorkerFromCache(t *testing.T) { |
| 215 | dur := 10 |
| 216 | p, _ := ants.NewPoolWithFuncGeneric(TestSize, demoPoolFuncInt) |
| 217 | defer p.Release() |
| 218 | |
| 219 | for i := 0; i < AntsSize; i++ { |
| 220 | _ = p.Invoke(dur) |
| 221 | } |
| 222 | time.Sleep(2 * ants.DefaultCleanIntervalTime) |
| 223 | _ = p.Invoke(dur) |
| 224 | t.Logf("pool with func, running workers number:%d", p.Running()) |
| 225 | mem := runtime.MemStats{} |
| 226 | runtime.ReadMemStats(&mem) |
| 227 | curMem = mem.TotalAlloc/MiB - curMem |
| 228 | t.Logf("memory usage:%d MB", curMem) |
| 229 | } |
| 230 | |
| 231 | func TestAntsPoolWithFuncGetWorkerFromCachePreMalloc(t *testing.T) { |
| 232 | dur := 10 |