Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add fiber trim functions #91

Merged
merged 1 commit into from
Jul 24, 2024
Merged

add fiber trim functions #91

merged 1 commit into from
Jul 24, 2024

Conversation

ReneWerner87
Copy link
Member

@ReneWerner87 ReneWerner87 commented Jul 23, 2024

Benchmark_TrimRight/fiber-12                  522399795        2.138 ns/op       0 B/op       0 allocs/op
Benchmark_TrimRight/fiber-12                  578245326        2.084 ns/op       0 B/op       0 allocs/op
Benchmark_TrimRight/default-12                345155300        3.380 ns/op       0 B/op       0 allocs/op
Benchmark_TrimRight/default-12                366972850        3.328 ns/op       0 B/op       0 allocs/op

Benchmark_TrimRightBytes/fiber-12             586471208        2.099 ns/op       0 B/op       0 allocs/op
Benchmark_TrimRightBytes/fiber-12             576055069        2.087 ns/op       0 B/op       0 allocs/op
Benchmark_TrimRightBytes/default-12           348849292        3.316 ns/op       0 B/op       0 allocs/op
Benchmark_TrimRightBytes/default-12           359904445        3.384 ns/op       0 B/op       0 allocs/op

Benchmark_TrimLeft/fiber-12                   578044544        2.122 ns/op       0 B/op       0 allocs/op
Benchmark_TrimLeft/fiber-12                   585290433        2.074 ns/op       0 B/op       0 allocs/op
Benchmark_TrimLeft/default-12                 351906888        3.667 ns/op       0 B/op       0 allocs/op
Benchmark_TrimLeft/default-12                 330852666        3.448 ns/op       0 B/op       0 allocs/op

Benchmark_TrimLeftBytes/fiber-12              545400109        2.239 ns/op       0 B/op       0 allocs/op
Benchmark_TrimLeftBytes/fiber-12              544800061        2.270 ns/op       0 B/op       0 allocs/op
Benchmark_TrimLeftBytes/default-12            329749006        3.521 ns/op       0 B/op       0 allocs/op
Benchmark_TrimLeftBytes/default-12            344199560        3.452 ns/op       0 B/op       0 allocs/op

Benchmark_Trim/fiber-12                       280692232        4.128 ns/op       0 B/op       0 allocs/op
Benchmark_Trim/fiber-12                       297070083        3.961 ns/op       0 B/op       0 allocs/op
Benchmark_Trim/default-12                     232522952        5.163 ns/op       0 B/op       0 allocs/op
Benchmark_Trim/default-12                     230659057        5.172 ns/op       0 B/op       0 allocs/op
Benchmark_Trim/default.trimspace-12           227328967        5.245 ns/op       0 B/op       0 allocs/op
Benchmark_Trim/default.trimspace-12           227340775        5.253 ns/op       0 B/op       0 allocs/op

Benchmark_TrimBytes/fiber-12                  275612090        4.280 ns/op       0 B/op       0 allocs/op
Benchmark_TrimBytes/fiber-12                  284892168        4.302 ns/op       0 B/op       0 allocs/op
Benchmark_TrimBytes/default-12                224021550        5.163 ns/op       0 B/op       0 allocs/op
Benchmark_TrimBytes/default-12                239689282        4.922 ns/op       0 B/op       0 allocs/op
Benchmark_TrimBytes/default.trimspace-12      216809300        5.514 ns/op       0 B/op       0 allocs/op
Benchmark_TrimBytes/default.trimspace-12      218177734        5.603 ns/op       0 B/op       0 allocs/op

Summary by CodeRabbit

  • New Features

    • Introduced new string trimming functions: TrimLeft, Trim, and TrimRight, enhancing string manipulation capabilities.
    • Added detailed benchmarks for these new functions, offering performance insights for users.
  • Bug Fixes

    • Improved test coverage with new test cases for the trimming functions, ensuring correct behavior across various scenarios.
  • Documentation

    • Enhanced README with performance benchmarks for string trimming functions, helping users assess efficiency.

```md

Benchmark_TrimRight/fiber-12                  522399795        2.138 ns/op       0 B/op       0 allocs/op
Benchmark_TrimRight/fiber-12                  578245326        2.084 ns/op       0 B/op       0 allocs/op
Benchmark_TrimRight/default-12                345155300        3.380 ns/op       0 B/op       0 allocs/op
Benchmark_TrimRight/default-12                366972850        3.328 ns/op       0 B/op       0 allocs/op

Benchmark_TrimRightBytes/fiber-12             586471208        2.099 ns/op       0 B/op       0 allocs/op
Benchmark_TrimRightBytes/fiber-12             576055069        2.087 ns/op       0 B/op       0 allocs/op
Benchmark_TrimRightBytes/default-12           348849292        3.316 ns/op       0 B/op       0 allocs/op
Benchmark_TrimRightBytes/default-12           359904445        3.384 ns/op       0 B/op       0 allocs/op

Benchmark_TrimLeft/fiber-12                   578044544        2.122 ns/op       0 B/op       0 allocs/op
Benchmark_TrimLeft/fiber-12                   585290433        2.074 ns/op       0 B/op       0 allocs/op
Benchmark_TrimLeft/default-12                 351906888        3.667 ns/op       0 B/op       0 allocs/op
Benchmark_TrimLeft/default-12                 330852666        3.448 ns/op       0 B/op       0 allocs/op

Benchmark_TrimLeftBytes/fiber-12              545400109        2.239 ns/op       0 B/op       0 allocs/op
Benchmark_TrimLeftBytes/fiber-12              544800061        2.270 ns/op       0 B/op       0 allocs/op
Benchmark_TrimLeftBytes/default-12            329749006        3.521 ns/op       0 B/op       0 allocs/op
Benchmark_TrimLeftBytes/default-12            344199560        3.452 ns/op       0 B/op       0 allocs/op

Benchmark_Trim/fiber-12                       280692232        4.128 ns/op       0 B/op       0 allocs/op
Benchmark_Trim/fiber-12                       297070083        3.961 ns/op       0 B/op       0 allocs/op
Benchmark_Trim/default-12                     232522952        5.163 ns/op       0 B/op       0 allocs/op
Benchmark_Trim/default-12                     230659057        5.172 ns/op       0 B/op       0 allocs/op
Benchmark_Trim/default.trimspace-12           227328967        5.245 ns/op       0 B/op       0 allocs/op
Benchmark_Trim/default.trimspace-12           227340775        5.253 ns/op       0 B/op       0 allocs/op

Benchmark_TrimBytes/fiber-12                  275612090        4.280 ns/op       0 B/op       0 allocs/op
Benchmark_TrimBytes/fiber-12                  284892168        4.302 ns/op       0 B/op       0 allocs/op
Benchmark_TrimBytes/default-12                224021550        5.163 ns/op       0 B/op       0 allocs/op
Benchmark_TrimBytes/default-12                239689282        4.922 ns/op       0 B/op       0 allocs/op
Benchmark_TrimBytes/default.trimspace-12      216809300        5.514 ns/op       0 B/op       0 allocs/op
Benchmark_TrimBytes/default.trimspace-12      218177734        5.603 ns/op       0 B/op       0 allocs/op
```
@ReneWerner87 ReneWerner87 requested a review from a team as a code owner July 23, 2024 20:53
@ReneWerner87 ReneWerner87 requested review from gaby, sixcolors and efectn and removed request for a team July 23, 2024 20:53
Copy link

coderabbitai bot commented Jul 23, 2024

Walkthrough

The recent changes introduce new string trimming functions and corresponding benchmarks, enhancing the functionality and performance measurement capabilities of the library. Specifically, the byteseq.go file now includes TrimLeft, Trim, and TrimRight functions, while the byteseq_test.go file expands the test coverage for these functions. The README.md file has been updated with performance benchmarks to guide users in optimizing string manipulation.

Changes

Files Change Summary
README.md Added benchmarks for TrimRight, TrimRightBytes, TrimLeft, TrimLeftBytes, Trim, and TrimBytes.
byteseq.go, byteseq_test.go Introduced TrimLeft, Trim, and TrimRight functions; updated benchmarks and tests for string trimming.

Poem

In the meadow where bytes play,
Trimming strings is the new way.
With each hop, we optimize,
Memory saved is our prize.
Oh, joyful code, let’s celebrate,
Efficiency is truly great! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @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.

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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

codecov bot commented Jul 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.48%. Comparing base (5aaa378) to head (71c3f5a).

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #91      +/-   ##
==========================================
+ Coverage   92.10%   92.48%   +0.37%     
==========================================
  Files           9        9              
  Lines         380      399      +19     
==========================================
+ Hits          350      369      +19     
  Misses         17       17              
  Partials       13       13              
Flag Coverage Δ
unittests 92.48% <100.00%> (+0.37%) ⬆️

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.

Copy link

@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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5aaa378 and 71c3f5a.

Files selected for processing (3)
  • README.md (2 hunks)
  • byteseq.go (1 hunks)
  • byteseq_test.go (2 hunks)
Additional comments not posted (20)
byteseq.go (3)

30-44: LGTM! Verify the function usage in the codebase.

The Trim function correctly removes leading and trailing characters specified in the cutset from a byte sequence.

However, ensure that all function calls to Trim are correctly implemented in the codebase.

Verification successful

LGTM! Verification successful.

The Trim function is correctly implemented and adequately tested in the byteseq_test.go file. No issues were found with its usage in the codebase.

  • byteseq_test.go: Verified test cases and benchmarks for Trim.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `Trim` match the new implementation.

# Test: Search for the function usage. Expect: Correct implementation.
rg --type go -A 5 $'Trim'

Length of output: 6984


21-27: LGTM! Verify the function usage in the codebase.

The TrimLeft function correctly removes leading characters specified in the cutset from a byte sequence.

However, ensure that all function calls to TrimLeft are correctly implemented in the codebase.

Verification successful

LGTM! Verify the function usage in the codebase.

The TrimLeft function is correctly implemented and used in the test cases and benchmarks. The function calls match the new implementation.

  • byteseq_test.go: Function calls to TrimLeft are correctly implemented and tested with both string and byte slice inputs.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `TrimLeft` match the new implementation.

# Test: Search for the function usage. Expect: Correct implementation.
rg --type go -A 5 $'TrimLeft'

Length of output: 2140


47-53: LGTM! Verify the function usage in the codebase.

The TrimRight function correctly removes trailing characters specified in the cutset from a byte sequence.

However, ensure that all function calls to TrimRight are correctly implemented in the codebase.

Verification successful

LGTM!

The TrimRight function is correctly implemented and thoroughly tested in byteseq_test.go for both string and byte slice inputs. The function usage is verified and no issues were found.

  • byteseq_test.go: Test cases and benchmarks for TrimRight.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `TrimRight` match the new implementation.

# Test: Search for the function usage. Expect: Correct implementation.
rg --type go -A 5 $'TrimRight'

Length of output: 2144

byteseq_test.go (11)

42-42: Approved: Addition of b.ReportAllocs().

The addition of b.ReportAllocs() enhances the benchmark by reporting memory allocations.


61-61: Approved: Addition of b.ReportAllocs().

The addition of b.ReportAllocs() enhances the benchmark by reporting memory allocations.


76-97: Approved: Comprehensive test cases.

The Test_TrimRight function includes comprehensive test cases that cover various scenarios, including edge cases.


99-118: Approved: Comprehensive benchmark.

The Benchmark_TrimRight function includes memory allocation reporting and compares the performance of the Fiber and default implementations.


120-139: Approved: Comprehensive benchmark.

The Benchmark_TrimRightBytes function includes memory allocation reporting and compares the performance of the Fiber and default implementations.


141-162: Approved: Comprehensive test cases.

The Test_TrimLeft function includes comprehensive test cases that cover various scenarios, including edge cases.


164-183: Approved: Comprehensive benchmark.

The Benchmark_TrimLeft function includes memory allocation reporting and compares the performance of the Fiber and default implementations.


185-204: Approved: Comprehensive benchmark.

The Benchmark_TrimLeftBytes function includes memory allocation reporting and compares the performance of the Fiber and default implementations.


206-228: Approved: Comprehensive test cases.

The Test_Trim function includes comprehensive test cases that cover various scenarios, including edge cases.


230-256: Approved: Comprehensive benchmark.

The Benchmark_Trim function includes memory allocation reporting and compares the performance of the Fiber and default implementations.


258-284: Approved: Comprehensive benchmark.

The Benchmark_TrimBytes function includes memory allocation reporting and compares the performance of the Fiber and default implementations.

README.md (6)

32-35: Approved: Benchmark results for Benchmark_TrimRight.

The results indicate that the Fiber implementation is significantly faster than the default implementation.


37-40: Approved: Benchmark results for Benchmark_TrimRightBytes.

The results indicate that the Fiber implementation is significantly faster than the default implementation.


42-45: Approved: Benchmark results for Benchmark_TrimLeft.

The results indicate that the Fiber implementation is significantly faster than the default implementation.


47-50: Approved: Benchmark results for Benchmark_TrimLeftBytes.

The results indicate that the Fiber implementation is significantly faster than the default implementation.


52-55: Approved: Benchmark results for Benchmark_Trim.

The results indicate that the Fiber implementation is significantly faster than the default implementation.


59-62: Approved: Benchmark results for Benchmark_TrimBytes.

The results indicate that the Fiber implementation is significantly faster than the default implementation.

Copy link
Member

@gaby gaby left a comment

Choose a reason for hiding this comment

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

LGTM

@ReneWerner87 ReneWerner87 merged commit 84e346c into master Jul 24, 2024
18 checks passed
@gaby gaby deleted the addTrimFunctions branch October 20, 2024 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants