-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
benchmarks loops should be ignored #13
Comments
The side-effect with I'll merge the naive fix but may rework it later to account for folks that use benchmarks which break this convention. |
Hello Sorry to re-open this issue, but this statement is wrong/incorrect:
If you read the official Go documentation https://pkg.go.dev/testing , it is now recommended to use the new syntax:
They don't mention the old syntax anywhere. Therefore I think this linter should suggest to rewrite benchmark that use the old syntax:
|
Thanks @pierrre you are absolutely correct and I have been planning to revert the change to exclude benchmarks. I think the proper solution here is to expose a setting to exclude patterns. Would you mind opening a new issue? If not I'll make a new issue when I have some time. To clarify the flaw in the initial issue, go benchmarks don't rely on a side-effect to adjust the number of iterations. The benchmark is evaluated multiple times before a measurement is taken and the value of |
Created #31 |
Describe the bug
Linter suggests to replace common benchmark loop.
Loop like
for i := 0; i < b.N; i++
is a standard go benchmark construct.Additionally, I think it's plain wrong to replace it with int range, because in that case
b.N
will be evaluated only once, while in for loopb.N
is evaluated every iteration, and I think it is important as it allows the bench framework to adapt to execution time.To Reproduce
Write a bench test.
Expected behavior
Linter should ignore such loops.
The text was updated successfully, but these errors were encountered: