Go test命令中的”-run -“标志可以更快地执行测试。

huangapple go评论77阅读模式
英文:

Go test "-run -" flag executed tests much faster

问题

我正在查看来自https://github.com/RoaringBitmap/roaring的一些基准测试。

当使用-run -运行特定基准测试时(如注释中所提到的):
go test -bench BenchmarkNexts -benchmem -run - 看起来执行速度更快,至少在不使用-run -运行时有5秒的初始开销,同时这也被绘制出来:

==roaring==
{1,2,3,4,5,100,1000}
{3,4,1000}
{}
Cardinality:  7
Contains 3?  true
1
3
4
5
1000

Wrote  22  bytes
I wrote the content to a byte stream and read it back.
size before run optimize: 1810 bytes, and after: 38 bytes.

由于-run标志根据正则表达式模式运行测试,似乎有一些被排除在外的内容,但具体是什么呢?两者运行相同的测试,唯一的区别是初始开销。

英文:

I was looking at some benchmark tests from https://github.com/RoaringBitmap/roaring

When running a specific benchmark using -run - (as mentioned in there comments):
go test -bench BenchmarkNexts -benchmem -run - It seems to execute faster, at least running it without -run - seems to have some initial overhead of 5 seconds also this is plotted:

==roaring==
{1,2,3,4,5,100,1000}
{3,4,1000}
{}
Cardinality:  7
Contains 3?  true
1
3
4
5
1000

Wrote  22  bytes
I wrote the content to a byte stream and read it back.
size before run optimize: 1810 bytes, and after: 38 bytes.

As the -run flag runs tests based on a regex pattern it seems like something is excluded here but what exactly as both run the same tests the only difference is the initial overhead.

答案1

得分: 3

> 运行 go test "-run -" 标志可以更快地执行测试。

这是预期的结果。当您不运行任何测试时,速度更快。

要查看正在执行的内容,请在 go test 命令中添加 -v 选项。

不运行任何测试:

go clean -testcache && go test -bench BenchmarkNexts -benchmem -run - -v

运行所有测试:

go clean -testcache && go test -bench BenchmarkNexts -benchmem -v

或者,由于 -run . 等同于运行所有测试,

go clean -testcache && go test -bench BenchmarkNexts -benchmem -run . -v

> Go 是管理 Go 源代码的工具。
>
> 测试标志
>
> -run regexp
> 仅运行与正则表达式匹配的测试、示例和模糊测试。
>
> -v
> 详细输出:记录所有运行的测试。
>
> 构建和测试缓存
>
> go 命令还会缓存成功的包测试结果。有关详细信息,请参阅 'go help test'。运行 'go clean -testcache' 将删除所有缓存的测试结果(但不会删除缓存的构建结果)。

英文:

> Go test "-run -" flag executed tests much faster

That is the expected result. It's faster when you don't run any tests.

To see what is being executed, add the -v option to your go test executions.

Run no tests:

go clean -testcache && go test -bench BenchmarkNexts -benchmem -run - -v

Run all tests:

go clean -testcache && go test -bench BenchmarkNexts -benchmem -v`

or, since -run . is equivalent to all tests,

go clean -testcache && go test -bench BenchmarkNexts -benchmem -run . -v

> Go is a tool for managing Go source code.
>
> Testing flags
>
> -run regexp
> Run only those tests, examples, and fuzz tests matching the regular
> expression.
>
> -v
> Verbose output: log all tests as they are run.
>
> Build and test caching
>
> The go command also caches successful package test results. See 'go help test' for details. Running 'go clean -testcache' removes all cached test results (but not cached build results).

huangapple
  • 本文由 发表于 2023年5月28日 16:42:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76350637.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定