Search code examples
gotestinggo-testingroaring-bitset

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


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.


Solution

  • 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).