Skip to content

Commit aa43afa

Browse files
committed
benchmark
1 parent 22e056a commit aa43afa

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

source/_posts/在-VS-Code-中调试和运行-Go-程序.md

+23-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ GoLand 打开项目时会自动初始化 `go mod tidy`,VS Code 不会,需要
3737
```json
3838
// 注意,这份配置应该位于 launch.json 的 configurations 字段下
3939
{
40-
"name": "Launch File", // 会显示在 VS Code 界面的人类可读的名字
40+
"name": "Launch File", // 会显示在 VS Code debug 界面的人类可读的名字
4141
"type": "go", // 声明为 go 语言的配置
4242
"request": "launch",
4343
"mode": "debug", // 支持断点调试
@@ -146,3 +146,25 @@ bufio.NewReader(os.Stdin)
146146
```
147147

148148
参考 [Stack Overflow](https://stackoverflow.com/questions/64786161/use-input-stdin-in-debug-console-vscode),也可以在 args 中配置标准输入重定向。
149+
150+
## Benchmark
151+
152+
除了基础的单元测试,也支持配置 go 内置的 benchmark。
153+
假设基准测试代码都在 `benchmark` 目录下。本质上也是 `go test -c` 然后执行构建的可执行文件。
154+
155+
```json
156+
{
157+
"name": "Benchmark",
158+
"type": "go",
159+
"request": "launch",
160+
"mode": "test",
161+
"program": "${workspaceFolder}\\benchmark",
162+
"output": "${workspaceFolder}\\benchmark\\benchmark",
163+
"args": [
164+
"-test.bench=^Benchmark", // 只关注 Benchmark 开头的函数
165+
"-test.v",
166+
"-test.run=^$",
167+
"-test.benchmem" // 查看内存分配信息
168+
]
169+
}
170+
```

0 commit comments

Comments
 (0)