optimization for go test

This commit is contained in:
Andy Pan 2018-08-04 10:34:02 +08:00
parent 87b15034c5
commit 1833ff6764
1 changed files with 21 additions and 18 deletions

View File

@ -32,6 +32,7 @@ import (
)
var n = 100000
var curMem uint64
func TestAntsPoolWithFunc(t *testing.T) {
var wg sync.WaitGroup
@ -50,7 +51,24 @@ func TestAntsPoolWithFunc(t *testing.T) {
t.Logf("pool with func, running workers number:%d", p.Running())
mem := runtime.MemStats{}
runtime.ReadMemStats(&mem)
t.Logf("memory usage:%d", mem.TotalAlloc/GiB)
curMem = mem.TotalAlloc / MiB - curMem
t.Logf("memory usage:%d", curMem)
}
func TestNoPool(t *testing.T) {
var wg sync.WaitGroup
for i := 0; i < n; i++ {
wg.Add(1)
go func() {
demoFunc()
wg.Done()
}()
}
wg.Wait()
mem := runtime.MemStats{}
runtime.ReadMemStats(&mem)
curMem = mem.TotalAlloc/MiB - curMem
t.Logf("memory usage:%d MB", curMem)
}
func TestAntsPool(t *testing.T) {
@ -72,23 +90,8 @@ func TestAntsPool(t *testing.T) {
mem := runtime.MemStats{}
runtime.ReadMemStats(&mem)
t.Logf("memory usage:%d MB", mem.TotalAlloc/MiB)
}
func TestNoPool(t *testing.T) {
var wg sync.WaitGroup
for i := 0; i < n; i++ {
wg.Add(1)
go func() {
demoFunc()
wg.Done()
}()
}
wg.Wait()
mem := runtime.MemStats{}
runtime.ReadMemStats(&mem)
t.Logf("memory usage:%d MB", mem.TotalAlloc/MiB)
curMem = mem.TotalAlloc/MiB - curMem
t.Logf("memory usage:%d MB", curMem)
}
func TestCodeCov(t *testing.T) {