Badges for Go Benchmark

kevincobain2000

Pulkit Kathuria

Posted on April 6, 2024

Badges for Go Benchmark

I would like to share a quick tip about adding badges to Github README for Go Benchmark tests.

Generally the benchmarks output is posted as it is on the README by repo owners. Example:

1000       8069938 ns/op     7360722 B/op      19794 allocs/op
2000       8272545 ns/op     7370076 B/op      19794 allocs/op
Enter fullscreen mode Exit fullscreen mode

Using the following action - it can be both measured and tracked over lifetime of a project.

Using it as a Badge in README

Image description

Using it as Tiny Widget in README

Image description

Using it as PR Comment

Image description

Image description

You can even view the history of all the benchmark tests within the PR for all commits, such as:

Image description

Method on how to add this is simple:

- uses: kevincobain2000/action-coveritup@v2
  with:
    type: allocs-per-op
    command: go test -count 1 -bench=. ./... -benchmem|grep allocs|awk '{ print $(--NF)}'
    record: score
    metric: alloc
Enter fullscreen mode Exit fullscreen mode

This method doesn't require publishing the results to separate gh-pages and has instant feedback feature which is helpful to the code reviewer when reviewing the code changes instantly.

Similarly - other metrics can also be recorded for test scores or lint errors etc.

Full details link: https://coveritup.app/
Full action's docs: https://github.com/kevincobain2000/action-coveritup
Live Demo pull req link: https://github.com/kevincobain2000/gobrew/pull/191

I hope you found something new in this post.
Thanks for reading.

💖 💪 🙅 🚩
kevincobain2000
Pulkit Kathuria

Posted on April 6, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Badges for Go Benchmark
go Badges for Go Benchmark

April 6, 2024