Skip to content

Add Go benchmark formatter#138

Merged
ReneWerner87 merged 3 commits intomasterfrom
codex/2025-07-13-20-39-55
Jul 14, 2025
Merged

Add Go benchmark formatter#138
ReneWerner87 merged 3 commits intomasterfrom
codex/2025-07-13-20-39-55

Conversation

@ReneWerner87
Copy link
Member

@ReneWerner87 ReneWerner87 commented Jul 13, 2025

Summary

  • replace the Python formatter with a Go version
  • expose new benchfmt make target

Testing

  • go test ./...

https://chatgpt.com/codex/tasks/task_e_687416e194ac8326a2b3412f4ec0bf5d

Summary by CodeRabbit

  • New Features

    • Added an automated tool to format benchmark tables in the README for improved readability.
  • Chores

    • Introduced a new build command to format benchmark results in documentation.

@ReneWerner87 ReneWerner87 requested a review from a team as a code owner July 13, 2025 20:40
@ReneWerner87 ReneWerner87 requested review from efectn, gaby and sixcolors and removed request for a team July 13, 2025 20:40
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 13, 2025

Walkthrough

A new Makefile target named benchfmt was introduced to automate formatting of benchmark tables in the README using a newly added Go script, format_benchmarks.go. The script reads and rewrites the README to align benchmark columns. The format target in the Makefile received minor reformatting.

Changes

File(s) Change Summary
Makefile Added benchfmt target to run the new Go script; minor reformatting of format target.
scripts/format_benchmarks.go Added new Go script to parse, align, and rewrite benchmark tables in README.md.
README.md Reformatted benchmark output lines for consistent column alignment and compact spacing.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Makefile
    participant GoScript as format_benchmarks.go
    participant README

    User->>Makefile: make benchfmt
    Makefile->>GoScript: go run ./scripts/format_benchmarks.go
    GoScript->>README: Read README.md
    GoScript->>GoScript: Parse and align benchmark lines
    GoScript->>README: Write formatted content back
Loading

Suggested labels

🧹 Updates

Poem

In the warren, code aligns,
Benchmarks tidy, all in lines.
With scripts that hop and targets new,
The README’s tables now look true.
A rabbit’s joy: neat columns, clear—
Formatting magic, far and near!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 371d103 and 28313c3.

📒 Files selected for processing (3)
  • Makefile (1 hunks)
  • README.md (1 hunks)
  • scripts/format_benchmarks.go (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • README.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • Makefile
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: ReneWerner87
PR: gofiber/recipes#0
File: :0-0
Timestamp: 2024-11-26T20:05:15.793Z
Learning: For future contributions to the `gofiber/recipes` repository, ensure that the tasks outlined in `.github/CONTRIBUTING.md` are incorporated, including creating a new directory without a "fiber" prefix, adding a `README.md` with Docusaurus metadata, and updating the overview by running `make generate`.
scripts/format_benchmarks.go (10)
Learnt from: juls0730
PR: gofiber/recipes#2710
File: tableflip/main.go:61-62
Timestamp: 2024-12-01T01:15:48.126Z
Learning: In the GoFiber `tableflip` recipe (`tableflip/main.go`), the implementation matches the upstream reference implementation. Future code suggestions should consider maintaining this alignment to ensure consistency.
Learnt from: norri
PR: gofiber/recipes#2701
File: clean-code/app/server/handlers/books.go:28-43
Timestamp: 2024-11-23T19:54:01.389Z
Learning: In 'clean-code/app/server/handlers/books.go', validation is out of scope and should not be suggested.
Learnt from: norri
PR: gofiber/recipes#2701
File: clean-code/app/datasources/database/memory_db.go:0-0
Timestamp: 2024-11-25T19:31:39.216Z
Learning: The `memoryDB` implementation in `clean-code/app/datasources/database/memory_db.go` is not intended for production use, so input validation, concurrency protection, and context usage are not required in this file.
Learnt from: norri
PR: gofiber/recipes#2701
File: clean-code/app/datasources/database/memory_db_test.go:0-0
Timestamp: 2024-11-25T19:36:45.661Z
Learning: In the `clean-code/app/datasources/database/memory_db.go`, the in-memory database implementation is not intended for production use. Therefore, adding extensive tests for concurrency and error handling in `memory_db_test.go` is unnecessary.
Learnt from: norri
PR: gofiber/recipes#2701
File: clean-code/app/datasources/database/memory_db.go:13-16
Timestamp: 2024-11-25T19:31:53.726Z
Learning: The `memoryDB` implementation in `clean-code/app/datasources/database/memory_db.go` is not intended for production use, so adding concurrency protection is not necessary.
Learnt from: efectn
PR: gofiber/fiber#3162
File: hooks_test.go:228-228
Timestamp: 2024-12-13T08:14:22.851Z
Learning: In Go test files, prefer using the `require` methods from the `testify` package for assertions instead of manual comparisons and calls to `t.Fatal` or `t.Fatalf`.
Learnt from: sixcolors
PR: gofiber/fiber#2922
File: middleware/cors/utils.go:63-71
Timestamp: 2024-10-08T19:06:06.583Z
Learning: The project uses the testify/assert package for assertions in unit tests.
Learnt from: sixcolors
PR: gofiber/fiber#2922
File: middleware/cors/utils.go:63-71
Timestamp: 2024-07-26T21:00:12.902Z
Learning: The project uses the testify/assert package for assertions in unit tests.
Learnt from: sixcolors
PR: gofiber/fiber#3016
File: middleware/session/store.go:164-167
Timestamp: 2024-10-02T23:03:31.727Z
Learning: Unit tests in this project use testify require.
Learnt from: sixcolors
PR: gofiber/fiber#3016
File: middleware/session/store.go:164-167
Timestamp: 2024-10-08T19:06:06.583Z
Learning: Unit tests in this project use testify require.
🪛 GitHub Check: codecov/patch
scripts/format_benchmarks.go

[warning] 11-15: scripts/format_benchmarks.go#L11-L15
Added lines #L11 - L15 were not covered by tests


[warning] 18-32: scripts/format_benchmarks.go#L18-L32
Added lines #L18 - L32 were not covered by tests


[warning] 34-64: scripts/format_benchmarks.go#L34-L64
Added lines #L34 - L64 were not covered by tests


[warning] 69-84: scripts/format_benchmarks.go#L69-L84
Added lines #L69 - L84 were not covered by tests


[warning] 87-98: scripts/format_benchmarks.go#L87-L98
Added lines #L87 - L98 were not covered by tests


[warning] 101-110: scripts/format_benchmarks.go#L101-L110
Added lines #L101 - L110 were not covered by tests


[warning] 113-116: scripts/format_benchmarks.go#L113-L116
Added lines #L113 - L116 were not covered by tests


[warning] 119-123: scripts/format_benchmarks.go#L119-L123
Added lines #L119 - L123 were not covered by tests


[warning] 126-131: scripts/format_benchmarks.go#L126-L131
Added lines #L126 - L131 were not covered by tests


[warning] 134-139: scripts/format_benchmarks.go#L134-L139
Added lines #L134 - L139 were not covered by tests


[warning] 142-142: scripts/format_benchmarks.go#L142
Added line #L142 was not covered by tests


[warning] 145-149: scripts/format_benchmarks.go#L145-L149
Added lines #L145 - L149 were not covered by tests


[warning] 152-156: scripts/format_benchmarks.go#L152-L156
Added lines #L152 - L156 were not covered by tests

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Build (1.24.x, windows-latest)
  • GitHub Check: Build (1.23.x, windows-latest)
  • GitHub Check: Compare
🔇 Additional comments (5)
scripts/format_benchmarks.go (5)

11-16: LGTM - Clean error handling.

The main function properly handles errors and exits with appropriate status code.


19-23: Security improvements properly implemented.

Good job addressing the security concerns from previous reviews with appropriate #nosec comments and nolint directives.


126-143: LGTM - Correct column width calculation.

The algorithm correctly determines maximum column widths for proper alignment.


145-150: LGTM - Correct left padding implementation.

Properly implements left padding for right-aligned columns.


152-157: LGTM - Correct right padding implementation.

Properly implements right padding for left-aligned columns.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/2025-07-13-20-39-55

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @ReneWerner87, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new Go-based formatter specifically designed to align benchmark results within the README.md file. It replaces a previous Python-based solution and integrates this new formatting capability into the project's Makefile for easy execution.

Highlights

  • New Go-based Benchmark Formatter: A new Go program (scripts/format_benchmarks.go) has been added. This script is designed to automatically format and align benchmark and memory allocation results found within Go code blocks in the README.md file, ensuring consistent presentation.
  • Dedicated benchfmt Make Target: A new make benchfmt command is now available. This target executes the newly introduced Go benchmark formatter, streamlining the process of keeping benchmark outputs consistently formatted in the README.md.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@codecov
Copy link

codecov bot commented Jul 13, 2025

Codecov Report

Attention: Patch coverage is 0% with 121 lines in your changes missing coverage. Please review.

Project coverage is 83.31%. Comparing base (d9dd7af) to head (28313c3).
Report is 13 commits behind head on master.

Files with missing lines Patch % Lines
scripts/format_benchmarks.go 0.00% 121 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master     #138       +/-   ##
===========================================
- Coverage   97.12%   83.31%   -13.81%     
===========================================
  Files          10       11        +1     
  Lines         730      851      +121     
===========================================
  Hits          709      709               
- Misses         14      135      +121     
  Partials        7        7               
Flag Coverage Δ
unittests 83.31% <0.00%> (-13.81%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (3)
scripts/format_benchmarks.go (3)

11-16: Address error handling best practice.

The error output in main should be handled properly according to static analysis.

 func main() {
 	if err := formatBenchmarks("README.md"); err != nil {
-		fmt.Fprintln(os.Stderr, err)
+		_, _ = fmt.Fprintln(os.Stderr, err)
 		os.Exit(1)
 	}
 }

44-44: Consider using a more specific regex pattern.

The current regex \S+ matches any non-whitespace sequence, which may be overly broad for parsing benchmark output.

-	re := regexp.MustCompile(`\S+`)
+	re := regexp.MustCompile(`[^\s]+`)

Or consider a more specific pattern if the benchmark format is well-defined:

re := regexp.MustCompile(`\w+[-\w.]*|\d+(?:\.\d+)?(?:ns|op|MB|allocs)/op`)

88-117: Consider extracting formatting logic into separate functions.

The formatting logic is complex and could benefit from extraction for better readability and testability.

func formatBenchmarkLine(toks []string, widths []int) string {
	formatted := make([]string, len(toks))
	for j, t := range toks {
		switch j {
		case 0:
			formatted[j] = padRight(t, widths[j])
		case 1, 2, 4, 6:
			formatted[j] = padLeft(t, widths[j])
		default:
			formatted[j] = t
		}
	}
	return strings.Join(formatted, "  ")
}

func formatMemoryLine(toks []string, widths []int) string {
	formatted := make([]string, len(toks))
	for j, t := range toks {
		switch j {
		case 0, 2:
			formatted[j] = padLeft(t, widths[j])
		default:
			formatted[j] = t
		}
	}
	return strings.Join(formatted, "  ")
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d9dd7af and 371d103.

📒 Files selected for processing (2)
  • Makefile (1 hunks)
  • scripts/format_benchmarks.go (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: ReneWerner87
PR: gofiber/recipes#0
File: :0-0
Timestamp: 2024-11-26T20:05:15.793Z
Learning: For future contributions to the `gofiber/recipes` repository, ensure that the tasks outlined in `.github/CONTRIBUTING.md` are incorporated, including creating a new directory without a "fiber" prefix, adding a `README.md` with Docusaurus metadata, and updating the overview by running `make generate`.
scripts/format_benchmarks.go (1)
Learnt from: juls0730
PR: gofiber/recipes#2710
File: tableflip/main.go:61-62
Timestamp: 2024-12-01T01:15:48.126Z
Learning: In the GoFiber `tableflip` recipe (`tableflip/main.go`), the implementation matches the upstream reference implementation. Future code suggestions should consider maintaining this alignment to ensure consistency.
🪛 GitHub Check: lint
scripts/format_benchmarks.go

[failure] 123-123:
G306: Expect WriteFile permissions to be 0600 or less (gosec)


[failure] 23-23:
Error return value of file.Close is not checked (errcheck)


[failure] 19-19:
G304: Potential file inclusion via variable (gosec)


[failure] 13-13:
Error return value of fmt.Fprintln is not checked (errcheck)


[failure] 13-13:
unhandled-error: Unhandled error in call to function fmt.Fprintln (revive)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: Analyse
  • GitHub Check: Compare
  • GitHub Check: Build (1.24.x, ubuntu-latest)
  • GitHub Check: Build (1.24.x, macos-13)
  • GitHub Check: Build (1.24.x, windows-latest)
  • GitHub Check: Build (1.24.x, macos-latest)
  • GitHub Check: Build (1.23.x, macos-latest)
  • GitHub Check: Build (1.23.x, windows-latest)
  • GitHub Check: Build (1.23.x, ubuntu-latest)
  • GitHub Check: Build (1.23.x, macos-13)
🔇 Additional comments (5)
scripts/format_benchmarks.go (3)

46-67: LGTM! Solid parsing logic with proper state management.

The code correctly:

  • Tracks Go code block boundaries
  • Identifies benchmark and memory allocation lines
  • Handles tab-to-space conversion
  • Maintains proper indexing for later formatting

126-143: LGTM! Efficient column width calculation.

The implementation correctly calculates maximum column widths across all entries, handling variable column counts properly.


145-157: LGTM! Clean and efficient padding functions.

Both padding functions handle edge cases properly and use efficient string operations.

Makefile (2)

29-29: Good fix! Proper tab indentation in Makefile.

The change from spaces to tab indentation follows Makefile conventions correctly.


31-34: LGTM! Well-integrated new target following project conventions.

The new benchfmt target:

  • Uses descriptive emoji and documentation comment
  • Marked as .PHONY correctly
  • Follows the same pattern as other targets
  • Provides easy access to the new Go-based benchmark formatter

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new Go script to format benchmark results in the README and adds a corresponding make target. The review includes a critical fix for the Makefile, and suggestions for the Go script to improve its correctness and robustness.

@ReneWerner87 ReneWerner87 merged commit 992fbd7 into master Jul 14, 2025
15 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant