Skip to content

Latest commit

 

History

History
40 lines (27 loc) · 723 Bytes

File metadata and controls

40 lines (27 loc) · 723 Bytes

一些实用且易遗漏的点

map使用的时候,如果value只是作为占位符

	mapp:=make(map[string]struct{},10)

推荐使用struct

因为空结构体变量的内存占用大小为0,而bool类型内存占用大小为1,这样可以更加最大化利用我们服务器的内存空间。

使用goleak监测goroutine泄露

import (
	"fmt"
	"sync"
	"testing"

	"go.uber.org/goleak"
)

func TestLeakWithGoleak(t *testing.T) {
	defer goleak.VerifyNone(t)
    // 具体的函数
	Goleak()
}

运行

$ go test -v -run ^TestLeakWithGoleak$

time可以显示执行时间

time go run xx.go 可以显示执行时间,包括 real, sys, user 的执行时间