Skip to content

testing: benchmark regexp doesn't filter top level benchmarks #20589

@josharian

Description

@josharian
package p

import "testing"

func BenchmarkMapA(b *testing.B) {}
func BenchmarkMapB(b *testing.B) {
	b.Run("C", func(b *testing.B) {})
}
$ go test -bench="Map/C" x_test.go 
goos: darwin
goarch: amd64
BenchmarkMapA-8   	2000000000	         0.00 ns/op
BenchmarkMapB/C-8 	2000000000	         0.00 ns/op
PASS
ok  	command-line-arguments	0.020s

The docs for -bench say:

	-bench regexp
	    Run (sub)benchmarks matching a regular expression.
	    The given regular expression is split into smaller ones by
	    top-level '/', where each must match the corresponding part of a
	    benchmark's identifier.

So I expected only benchmarks matching Map in the first part and C in the second part to match--namely BenchmarkMapB/C. But I got BenchmarkMapA as well.

This arose because I wanted to run only the runtime map sub-benchmarks named "Int64" and the natural command go test -bench="Map/Int64" -run=NONE runtime did not work.

cc @mpvl

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions