| 246 | } |
| 247 | |
| 248 | func TestAntsPoolWithFuncGenericGetWorkerFromCachePreMalloc(t *testing.T) { |
| 249 | dur := 10 |
| 250 | p, _ := ants.NewPoolWithFuncGeneric(TestSize, demoPoolFuncInt, ants.WithPreAlloc(true)) |
| 251 | defer p.Release() |
| 252 | |
| 253 | for i := 0; i < AntsSize; i++ { |
| 254 | _ = p.Invoke(dur) |
| 255 | } |
| 256 | time.Sleep(2 * ants.DefaultCleanIntervalTime) |
| 257 | _ = p.Invoke(dur) |
| 258 | t.Logf("pool with func, running workers number:%d", p.Running()) |
| 259 | mem := runtime.MemStats{} |
| 260 | runtime.ReadMemStats(&mem) |
| 261 | curMem = mem.TotalAlloc/MiB - curMem |
| 262 | t.Logf("memory usage:%d MB", curMem) |
| 263 | } |
| 264 | |
| 265 | // Contrast between goroutines without a pool and goroutines with ants pool. |
| 266 | |