miller
发布于

go 工具链 (未完待续)

1. package

  • go mod init maocaoying.com/learn
  • go mod tidy
  • go install // install cmd into GOPTAH
  • go get // 感觉废弃了,直接go mod tidy

2. go help cmd

// help cmd detail info


3. test

  • go test [-v] learn_test.go // 指定文件 默认所有testfunc
  • go test -v -run TestA select_test.go // TestA func. TestA* 正则匹配的都会执行
  • go test -v -bench=. benchmark_test.go
  • go test -v -bench=. -benchtime=5s benchmark_test.go
  • go test -v -bench=Alloc -benchmem benchmark_test.go 内存分配
  // 重置计时器
  b.ResetTimer()
  // 停止计时器
  b.StopTimer()
  // 开始计时器
  b.StartTimer()

4. 调试 优化

 $ go test -race mypkg
$ go run -race mysrc.go
$ go build -race mycmd
$ go install -race mypkg
浏览 (133)
点赞
收藏
评论