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 function _get_line_range by 12% in src/black/ranges.py #53

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 14, 2024

📄 _get_line_range in src/black/ranges.py

✨ Performance Summary:

  • Speed Increase: 📈 12% (0.12x faster)
  • Runtime Reduction: ⏱️ From 9.13 microseconds down to 8.12 microseconds (best of 69 runs)

📝 Explanation and details

Sure, here is an optimized version of the program.


Correctness verification

The new optimized code was tested for correctness. The results are listed below:

Test Status Details
⚙️ Existing Unit Tests 🔘 None Found
🌀 Generated Regression Tests 5 Passed See below
⏪ Replay Tests 🔘 None Found
🔎 Concolic Coverage Tests 🔘 None Found
📊 Coverage 36.8%

🌀 Generated Regression Tests Details

Click to view details
from collections.abc import Iterator
from typing import Optional, Union

# imports
import pytest  # used for our unit tests
from black.ranges import _get_line_range
from blib2to3.pgen2.token import NEWLINE
from blib2to3.pytree import Leaf, Node

# function to test
LN = Union[Leaf, Node]
from black.ranges import _get_line_range

# unit tests






def test_empty_list():
    # Empty list of nodes
    codeflash_output = _get_line_range([])







from collections.abc import Iterator
from typing import Optional, Union

# imports
import pytest  # used for our unit tests
from black.ranges import _get_line_range
from blib2to3.pgen2.token import NEWLINE
from blib2to3.pytree import Leaf, Node

# function to test
LN = Union[Leaf, Node]
from black.ranges import _get_line_range

# unit tests

def test_single_line_leaf_node():
    leaf = Leaf(1, "x = 1")
    leaf.lineno = 1
    codeflash_output = _get_line_range(leaf)

def test_multi_line_leaf_node():
    leaf = Leaf(1, "'''multi\nline\nstring'''")
    leaf.lineno = 1
    codeflash_output = _get_line_range(leaf)



def test_empty_list():
    codeflash_output = _get_line_range([])

📣 **Feedback**

If you have any feedback or need assistance, feel free to join our Discord community:

Discord

Sure, here is an optimized version of the program.
@codeflash-ai codeflash-ai bot added the ⚡️ codeflash Optimization PR opened by Codeflash AI label Dec 14, 2024
@codeflash-ai codeflash-ai bot requested a review from misrasaurabh1 December 14, 2024 03:46
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