Run only benchmark in go(lang)
a quick go(lang) tip
let’s say you have tests and benchmarks in your codebase and you want to run only benchmarks, or to put in other words, to filter out all tests from being executed
unfortunately there’s no --bench-only
nor anything similar available,
but there’s a trick popular in the community that does the job
the idea is to basically filter out all tests with an unlikely regex
|
|
but of course we can do better with a clever regex
|
|
as you may be aware, ^
matches the beginning of a string and $
the end
so it tries to match a string that’s empty
naturally there’s no test with empty name, otherwise the parser would fail, i think
therefore it ends up filtering out all tests, so only benchmarks run
one minor inconvenience is that in the fish shell we need to escape the $
:
|
|