mapp:=make(map[string]struct{},10)推荐使用struct。
因为空结构体变量的内存占用大小为0,而bool类型内存占用大小为1,这样可以更加最大化利用我们服务器的内存空间。
import (
"fmt"
"sync"
"testing"
"go.uber.org/goleak"
)
func TestLeakWithGoleak(t *testing.T) {
defer goleak.VerifyNone(t)
// 具体的函数
Goleak()
}运行
$ go test -v -run ^TestLeakWithGoleak$time go run xx.go 可以显示执行时间,包括 real, sys, user 的执行时间