A benchmark changes b.N, which the testing package sets and divides by
What it finds
b.N = 1000 in a benchmark: the testing package chooses b.N and runs the benchmark with growing values until the timing is stable, then divides the time by it. A benchmark that sets it itself reports a time per operation that is wrong.
Reported are assignments and increments of the field N of a parameter declared as *testing.B.
From the rule's source, benchmark_n_assigned.rs.
package p import "testing" func BenchmarkParse(b *testing.B) { b.N = 1000tx0 reports: b.N is set by the testing package for i := 0; i < b.N; i++ { b.N++tx0 reports: b.N is set by the testing package }} type counter struct{ N int } func g(b *counter) { b.N = 3} Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/go:benchmark-n-assigned" = "off"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/go:benchmark-n-assigned] reason="..."tx0 explain tx0/go:benchmark-n-assigned shows the same in the terminal. Found a false positive? Report it.