Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions benchmark.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import timeit
import re

Copilot AI Mar 21, 2026

Copy link

Choose a reason for hiding this comment

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

import re at module top is unused in this benchmark script (the regex module is only imported inside the timeit setup strings). Please remove the unused import to avoid lint failures and reduce confusion about what the benchmark depends on.

Suggested change
import re

Copilot uses AI. Check for mistakes.

content = """[package]
name = "test"
Comment on lines +1 to +5

Copilot AI Mar 21, 2026

Copy link

Choose a reason for hiding this comment

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

This PR adds benchmark.py at the repository root, but it isn't referenced by docs, CI, or the scripts/ tooling. Consider moving it under a dedicated location (e.g., scripts/bench/ or tools/) or excluding it from the PR to avoid leaving an orphan utility at the top level.

Copilot uses AI. Check for mistakes.
version = "1.0.0"

[source]
url = "http://example.com"
sha256 = "1234"

[bottle.macos-arm64]
url = "http://example.com/bottle1"
sha256 = "abcd"

[bottle.linux-x86_64]
url = "http://example.com/bottle2"
sha256 = "efgh"

[build]
commands = ["make"]
"""

setup_unoptimized = """
import re
content = %r
""" % content

stmt_unoptimized = """
last_bottle_end = -1
for m in re.finditer(
r'\\[bottle\\.[^\\]]+\\][ \\t]*\\n'
r'url[ \\t]*=[ \\t]*"[^"]*"[ \\t]*\\n'
r'sha256[ \\t]*=[ \\t]*"[^"]*"[ \\t]*\\n',
content,
):
last_bottle_end = m.end()
"""

setup_optimized = """
import re
content = %r
BOTTLE_SECTION_PATTERN = re.compile(
r'\\[bottle\\.[^\\]]+\\][ \\t]*\\n'
r'url[ \\t]*=[ \\t]*"[^"]*"[ \\t]*\\n'
r'sha256[ \\t]*=[ \\t]*"[^"]*"[ \\t]*\\n'
)
""" % content

stmt_optimized = """
last_bottle_end = -1
for m in BOTTLE_SECTION_PATTERN.finditer(content):
last_bottle_end = m.end()
"""

if __name__ == '__main__':
n = 100000
unopt_time = timeit.timeit(stmt_unoptimized, setup=setup_unoptimized, number=n)
opt_time = timeit.timeit(stmt_optimized, setup=setup_optimized, number=n)

print(f"Unoptimized time: {unopt_time:.6f}s")
print(f"Optimized time: {opt_time:.6f}s")
if unopt_time > 0:
improvement = (unopt_time - opt_time) / unopt_time * 100
print(f"Improvement: {improvement:.2f}%")
14 changes: 8 additions & 6 deletions scripts/update-bottles.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
from pathlib import Path


BOTTLE_SECTION_PATTERN = re.compile(
r'\[bottle\.[^\]]+\][ \t]*\n'
r'url[ \t]*=[ \t]*"[^"]*"[ \t]*\n'
r'sha256[ \t]*=[ \t]*"[^"]*"[ \t]*\n'
)


def update_bottle_section(
content: str, platform: str, url: str, sha256: str
) -> str:
Expand Down Expand Up @@ -60,12 +67,7 @@ def update_bottle_section(

# Check if other bottle sections exist — insert after the last one
last_bottle_end = -1
for m in re.finditer(
r'\[bottle\.[^\]]+\][ \t]*\n'
r'url[ \t]*=[ \t]*"[^"]*"[ \t]*\n'
r'sha256[ \t]*=[ \t]*"[^"]*"[ \t]*\n',
content,
):
for m in BOTTLE_SECTION_PATTERN.finditer(content):
last_bottle_end = m.end()

if last_bottle_end > 0:
Expand Down
Loading