DEV Community

Pulkit Kathuria
Pulkit Kathuria

Posted on

1

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.

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs