Skip to content

Add uncompress benchmark#1860

Merged
Dead2 merged 2 commits intodevelopfrom
bench_uncompress
Feb 1, 2025
Merged

Add uncompress benchmark#1860
Dead2 merged 2 commits intodevelopfrom
bench_uncompress

Conversation

@Dead2
Copy link
Copy Markdown
Member

@Dead2 Dead2 commented Jan 29, 2025

Adds uncompress benchmark.
Also fix two minor warnings in other benchmarks.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added new benchmarking capabilities for uncompression performance testing
    • Introduced comprehensive performance measurement for uncompress() function
  • Bug Fixes

    • Initialized previously uninitialized variables in benchmark tests to improve reliability
  • Tests

    • Enhanced benchmark test suite with more robust performance measurement methods
    • Added detailed benchmarking for compression and uncompression operations

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jan 29, 2025

Walkthrough

This pull request introduces several modifications to the benchmarking suite for compression and uncompression functions. The changes include adding a new benchmark file for uncompression performance testing, initializing variables in existing benchmark files to improve consistency, and updating the CMakeLists.txt to include the new benchmark source file. The modifications aim to enhance the testing infrastructure for compression-related functions by providing more comprehensive performance measurement capabilities.

Changes

File Change Summary
test/benchmarks/CMakeLists.txt Added benchmark_uncompress.cc to benchmark_zlib executable target
test/benchmarks/benchmark_compare256_rle.cc Initialized len variable to zero in Bench method
test/benchmarks/benchmark_compress.cc Initialized err variable to zero in Bench method
test/benchmarks/benchmark_uncompress.cc New benchmark file for uncompress() function performance testing

Sequence Diagram

sequenceDiagram
    participant Benchmark as Benchmark Framework
    participant UncompressBench as Uncompress Benchmark
    participant Uncompress as Uncompress Function

    Benchmark->>UncompressBench: SetUp
    UncompressBench-->>Benchmark: Allocate Buffers
    UncompressBench->>UncompressBench: Compress Test Data

    Benchmark->>UncompressBench: Bench
    UncompressBench->>Uncompress: Call uncompress()
    Uncompress-->>UncompressBench: Return Decompressed Data
    
    Benchmark->>UncompressBench: TearDown
    UncompressBench-->>Benchmark: Free Allocated Buffers
Loading

Possibly related PRs

Suggested reviewers

  • nmoinvaz
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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>, please review it.
    • 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 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 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 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. (Beta)
  • @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 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
Copy Markdown
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: 0

🧹 Nitpick comments (2)
test/benchmarks/benchmark_uncompress.cc (2)

20-21: Consider making MAX_SIZE and NUM_TESTS configurable.

These constants could be made configurable through CMake variables to allow for different test configurations without code changes.


67-70: Consider using a map for O(1) size lookup.

The linear search in the benchmark loop could be replaced with a map for better performance:

private:
+    std::unordered_map<int64_t, size_t> size_to_index;
    // ... other members ...

public:
    void SetUp(const ::benchmark::State& state) {
        // ... existing setup ...
        for (size_t i = 0; i < NUM_TESTS; ++i) {
+           size_to_index[sizes[i]] = i;
            // ... rest of the setup ...
        }
    }

    void Bench(benchmark::State& state) {
        int err = 0;
        for (auto _ : state) {
-           int index = 0;
-           while (sizes[index] != state.range(0)) ++index;
+           int index = size_to_index[state.range(0)];
            // ... rest of the benchmark ...
        }
    }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a0fa247 and c89918e.

📒 Files selected for processing (4)
  • test/benchmarks/CMakeLists.txt (1 hunks)
  • test/benchmarks/benchmark_compare256_rle.cc (1 hunks)
  • test/benchmarks/benchmark_compress.cc (1 hunks)
  • test/benchmarks/benchmark_uncompress.cc (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (20)
  • GitHub Check: EL9 Clang S390X DFLTCC MSAN
  • GitHub Check: macOS GCC
  • GitHub Check: EL9 Clang S390X DFLTCC MSAN
  • GitHub Check: macOS GCC
  • GitHub Check: EL9 Clang S390X DFLTCC MSAN
  • GitHub Check: macOS GCC
  • GitHub Check: EL9 Clang S390X DFLTCC MSAN
  • GitHub Check: macOS GCC
  • GitHub Check: EL9 Clang S390X DFLTCC MSAN
  • GitHub Check: macOS GCC
  • GitHub Check: EL9 Clang S390X DFLTCC MSAN
  • GitHub Check: macOS GCC
  • GitHub Check: EL9 Clang S390X DFLTCC MSAN
  • GitHub Check: macOS GCC
  • GitHub Check: EL9 Clang S390X DFLTCC MSAN
  • GitHub Check: macOS GCC
  • GitHub Check: EL9 Clang S390X DFLTCC MSAN
  • GitHub Check: macOS GCC
  • GitHub Check: EL9 Clang S390X DFLTCC MSAN
  • GitHub Check: macOS GCC
🔇 Additional comments (5)
test/benchmarks/benchmark_compress.cc (1)

46-46: LGTM! Good practice to initialize the variable.

Initializing err to 0 before use prevents potential undefined behavior and silences compiler warnings.

test/benchmarks/benchmark_compare256_rle.cc (1)

36-36: LGTM! Good practice to initialize the variable.

Initializing len to 0 before use prevents potential undefined behavior and silences compiler warnings.

test/benchmarks/benchmark_uncompress.cc (2)

88-94: LGTM! Consistent with other benchmarks.

The benchmark registration follows the established pattern and uses appropriate test sizes.


54-61: Consider validating compressed size.

It would be good to verify that the compressed size is within expected bounds:

            uLong compressed_size = maxlen;
            int err = PREFIX(compress)(compressed_buff[i], &compressed_size, inbuff, sizes[i]);
            if (err != Z_OK) {
                fprintf(stderr, "Compression failed with error %d\n", err);
                abort();
            }
+           if (compressed_size >= maxlen) {
+               fprintf(stderr, "Compressed size %lu exceeds buffer size %lu\n", compressed_size, maxlen);
+               abort();
+           }
            compressed_sizes[i] = compressed_size;
test/benchmarks/CMakeLists.txt (1)

51-51: LGTM! Correctly added to benchmark target.

The new benchmark file is properly added to the benchmark_zlib target and maintains alphabetical ordering.

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 29, 2025

Codecov Report

Attention: Patch coverage is 82.75862% with 5 lines in your changes missing coverage. Please review.

Project coverage is 80.36%. Comparing base (a0fa247) to head (c89918e).
Report is 2 commits behind head on develop.

Files with missing lines Patch % Lines
test/benchmarks/benchmark_uncompress.cc 82.75% 2 Missing and 3 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1860      +/-   ##
===========================================
+ Coverage    80.34%   80.36%   +0.01%     
===========================================
  Files          138      139       +1     
  Lines        11147    11178      +31     
  Branches      2860     2868       +8     
===========================================
+ Hits          8956     8983      +27     
+ Misses        1223     1221       -2     
- Partials       968      974       +6     

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant