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

⚡️ Speed up method ProgressBar.format_pct by 5% #22

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

codeflash-ai[bot]
Copy link

@codeflash-ai codeflash-ai bot commented Dec 19, 2024

📄 5% (0.05x) speedup for ProgressBar.format_pct in src/click/_termui_impl.py

⏱️ Runtime : 1.51 millisecond 1.43 millisecond (best of 30 runs)

📝 Explanation and details

Here is the optimized version of the ProgressBar class.

  1. Combined conditional assignments to reduce redundancy.

Correctness verification report:

Test Status
⚙️ Existing Unit Tests 🔘 None Found
🌀 Generated Regression Tests 1002 Passed
⏪ Replay Tests 🔘 None Found
🔎 Concolic Coverage Tests 🔘 None Found
📊 Tests Coverage 100.0%
🌀 Generated Regression Tests Details
from __future__ import annotations

import collections.abc as cabc
import time
import typing as t
from io import StringIO
from types import TracebackType

# imports
import pytest  # used for our unit tests
from src.click._compat import _default_text_stdout, isatty
from src.click._termui_impl import ProgressBar

# unit tests

# Helper function to create ProgressBar instance with specific pct
def create_progress_bar_with_pct(pct):
    pb = ProgressBar(iterable=range(1))
    pb.pct = pct
    return pb

# Basic Functionality




















from __future__ import annotations

import collections.abc as cabc
import time
import typing as t
from io import StringIO
from types import TracebackType

# imports
import pytest  # used for our unit tests
from src.click._compat import _default_text_stdout, isatty
from src.click._termui_impl import ProgressBar


# unit tests
class TestProgressBar:
    @pytest.fixture
    def progress_bar(self):
        class MockProgressBar:
            def __init__(self, pct):
                self.pct = pct

            def format_pct(self):
                return f"{int(self.pct * 100): 4}%"[1:]

        return MockProgressBar

📢 Feedback on this optimization? Discord

Here is the optimized version of the `ProgressBar` class.

1. Combined conditional assignments to reduce redundancy.
@codeflash-ai codeflash-ai bot added the ⚡️ codeflash Optimization PR opened by Codeflash AI label Dec 19, 2024
@codeflash-ai codeflash-ai bot requested a review from alvin-r December 19, 2024 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚡️ codeflash Optimization PR opened by Codeflash AI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants