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.

👋 While you are here

Reinvent your career. Join DEV.

It takes one minute and is worth it for your career.

Get started

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

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay