René's URL Explorer Experiment


Title: gh-130167: Improve speed of `ftplib.parse150` by replacing `re` by donbarbos · Pull Request #130243 · python/cpython · GitHub

Open Graph Title: gh-130167: Improve speed of `ftplib.parse150` by replacing `re` by donbarbos · Pull Request #130243 · python/cpython

X Title: gh-130167: Improve speed of `ftplib.parse150` by replacing `re` by donbarbos · Pull Request #130243 · python/cpython

Description: I also suggest adding tests for this function because they are missing in the Lib/test/test_ftplib.py file. I wrote tests (would be in next comment) and benchmarks (results here) parse150_bench.py: from Lib.ftplib import error_reply import timeit # Regex version _150_re = None def parse150_re(resp): if resp[:3] != "150": raise error_reply(resp) global _150_re if _150_re is None: import re _150_re = re.compile(r"150 .* \((\d+) bytes\)", re.IGNORECASE | re.ASCII) m = _150_re.match(resp) if not m: return None return int(m.group(1)) # No regex version def parse150(resp): if not resp.startswith("150"): raise error_reply(resp) start = resp.find("(") end = resp.find(" bytes)") if start == -1 or end == -1 or start >= end: return None try: return int(resp[start + 1 : end]) except ValueError: return None test_cases = [ "150 Opening BINARY mode data connection (4096 bytes)", "150 Transfer starting (32768 bytes)", "150 Data connection accepted (131072 bytes)", "150 Some random message without bytes", "150 Large file transfer (987654321 bytes)", "150 Small file (1 bytes)", "150 Transfer starting (99999999 bytes)", "150 Weird case (42 bytes) with extra text", ] for case in test_cases: regex_time = timeit.timeit(lambda: parse150_re(case), number=1_000_000) no_regex_time = timeit.timeit(lambda: parse150(case), number=1_000_000) print(f"Test case: {case}") print(f" Regex version: {regex_time:.6f} sec") print(f" No regex version: {no_regex_time:.6f} sec") Results for different cases (from x1.82 to x1.92 as fast): $ ./python -B parse150_bench.py Test case: 150 Opening BINARY mode data connection (4096 bytes) Regex version: 1.147499 sec No regex version: 0.630863 sec Test case: 150 Transfer starting (32768 bytes) Regex version: 1.113087 sec No regex version: 0.610494 sec Test case: 150 Data connection accepted (131072 bytes) Regex version: 1.140198 sec No regex version: 0.616784 sec Test case: 150 Some random message without bytes Regex version: 0.643958 sec No regex version: 0.302508 sec Test case: 150 Large file transfer (987654321 bytes) Regex version: 1.160474 sec No regex version: 0.605776 sec Test case: 150 Small file (1 bytes) Regex version: 1.005945 sec No regex version: 0.522877 sec Test case: 150 Transfer starting (99999999 bytes) Regex version: 1.147927 sec No regex version: 0.616777 sec Test case: 150 Weird case (42 bytes) with extra text Regex version: 1.140925 sec No regex version: 0.592486 sec Issue: gh-130167

Open Graph Description: I also suggest adding tests for this function because they are missing in the Lib/test/test_ftplib.py file. I wrote tests (would be in next comment) and benchmarks (results here) parse150_bench.py:...

X Description: I also suggest adding tests for this function because they are missing in the Lib/test/test_ftplib.py file. I wrote tests (would be in next comment) and benchmarks (results here) parse150_bench.py:...

Opengraph URL: https://github.com/python/cpython/pull/130243

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/checks(.:format)
route-controllerpull_requests
route-actionchecks
fetch-noncev2:5bd5cc53-481e-6469-668c-492938a77218
current-catalog-service-hash87dc3bc62d9b466312751bfd5f889726f4f1337bdff4e8be7da7c93d6c00a25a
request-idD4C6:26177F:C472A8:FD1166:696B28DE
html-safe-nonce1b14b8435239adefcd3bd0caf3cd71e0d7e7f97df621720a86622a4d1776680e
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENEM2OjI2MTc3RjpDNDcyQTg6RkQxMTY2OjY5NkIyOERFIiwidmlzaXRvcl9pZCI6IjQwMTcxMjQ2OTUxNTkyODU5ODIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmaccce360425753a5e0ab096b85ddb773a5821015cec7931050bea780923a33af17
hovercard-subject-tagpull_request:2340839963
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,checks,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/checks
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/python/cpython/pull/130243/checks
twitter:imagehttps://avatars.githubusercontent.com/u/47272787?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/47272787?s=400&v=4
og:image:altI also suggest adding tests for this function because they are missing in the Lib/test/test_ftplib.py file. I wrote tests (would be in next comment) and benchmarks (results here) parse150_bench.py:...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None5f99f7c1d70f01da5b93e5ca90303359738944d8ab470e396496262c66e60b8d
turbo-cache-controlno-cache
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive full-width full-width-p-0
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release82560a55c6b2054555076f46e683151ee28a19bc
ui-targetcanary-1
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/pull/130243/checks#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F130243%2Fchecks
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F130243%2Fchecks
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Fchecks&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/pull/130243/checks
Reloadhttps://github.com/python/cpython/pull/130243/checks
Reloadhttps://github.com/python/cpython/pull/130243/checks
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/pull/130243/checks
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 33.9k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 71.1k https://github.com/login?return_to=%2Fpython%2Fcpython
Code https://github.com/python/cpython
Issues 5k+ https://github.com/python/cpython/issues
Pull requests 2.1k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects 31 https://github.com/python/cpython/projects
Security Uh oh! There was an error while loading. Please reload this page. https://github.com/python/cpython/security
Please reload this pagehttps://github.com/python/cpython/pull/130243/checks
Insights https://github.com/python/cpython/pulse
Code https://github.com/python/cpython
Issues https://github.com/python/cpython/issues
Pull requests https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
donbarboshttps://github.com/donbarbos
python:mainhttps://github.com/python/cpython/tree/main
donbarbos:improve-parse150-speedhttps://github.com/donbarbos/cpython/tree/improve-parse150-speed
Conversation 5 https://github.com/python/cpython/pull/130243
Commits 5 https://github.com/python/cpython/pull/130243/commits
Checks 35 https://github.com/python/cpython/pull/130243/checks
Files changed https://github.com/python/cpython/pull/130243/files
Please reload this pagehttps://github.com/python/cpython/pull/130243/checks
Please reload this pagehttps://github.com/python/cpython/pull/130243/checks
Sign in for the full log viewhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F130243%2Fchecks
gh-130167: Improve speed of ftplib.parse150 by replacing re https://github.com/python/cpython/pull/130243/checks#top
Please reload this pagehttps://github.com/python/cpython/pull/130243/checks
Check labels on: pull_request https://github.com/python/cpython/actions/runs/13396977651
DO-NOT-MERGE https://github.com/python/cpython/actions/runs/13396977651/job/37418353732?pr=130243
Unresolved review https://github.com/python/cpython/actions/runs/13396977651/job/37418354127?pr=130243
Lint on: pull_request https://github.com/python/cpython/actions/runs/13396977656
lint https://github.com/python/cpython/actions/runs/13396977656/job/37418354025?pr=130243
Tests on: pull_request https://github.com/python/cpython/actions/runs/13396977667
Change detection / Create context from changed files https://github.com/python/cpython/actions/runs/13396977667/job/37418354330?pr=130243
Docs / Docs https://github.com/python/cpython/actions/runs/13396977667/job/37418382238?pr=130243
Docs / Doctest https://github.com/python/cpython/actions/runs/13396977667/job/37418382698?pr=130243
Check if Autoconf files are up to date https://github.com/python/cpython/actions/runs/13396977667/job/37418369691?pr=130243
Check if generated files are up to date https://github.com/python/cpython/actions/runs/13396977667/job/37418370503?pr=130243
Windows / build and test (x64) https://github.com/python/cpython/actions/runs/13396977667/job/37418378480?pr=130243
Windows (free-threading) / build and test (x64) https://github.com/python/cpython/actions/runs/13396977667/job/37418378856?pr=130243
Windows / build (arm64) https://github.com/python/cpython/actions/runs/13396977667/job/37418376441?pr=130243
Windows (free-threading) / build (arm64) https://github.com/python/cpython/actions/runs/13396977667/job/37418377939?pr=130243
Windows / build and test (Win32) https://github.com/python/cpython/actions/runs/13396977667/job/37418376816?pr=130243
Windows MSI${{ '' }} https://github.com/python/cpython/actions/runs/13396977667/job/37418373348?pr=130243
macOS / build and test (ghcr.io/cirruslabs/macos-runner:sonoma) https://github.com/python/cpython/actions/runs/13396977667/job/37418377542?pr=130243
macOS (free-threading) / build and test (ghcr.io/cirruslabs/macos-runner:sonoma) https://github.com/python/cpython/actions/runs/13396977667/job/37418377213?pr=130243
macOS / build and test (macos-13) https://github.com/python/cpython/actions/runs/13396977667/job/37418379330?pr=130243
Ubuntu / build and test (ubuntu-24.04) https://github.com/python/cpython/actions/runs/13396977667/job/37418380802?pr=130243
Ubuntu / build and test (ubuntu-22.04-arm) https://github.com/python/cpython/actions/runs/13396977667/job/37418380435?pr=130243
Ubuntu (free-threading) / build and test (ubuntu-24.04) https://github.com/python/cpython/actions/runs/13396977667/job/37418381903?pr=130243
Ubuntu (free-threading) / build and test (ubuntu-22.04-arm) https://github.com/python/cpython/actions/runs/13396977667/job/37418381126?pr=130243
Ubuntu (bolt) / build and test (ubuntu-24.04) https://github.com/python/cpython/actions/runs/13396977667/job/37418381516?pr=130243
Ubuntu SSL tests with OpenSSL (ubuntu-24.04, 3.0.15) https://github.com/python/cpython/actions/runs/13396977667/job/37418371927?pr=130243
Ubuntu SSL tests with OpenSSL (ubuntu-24.04, 3.1.7) https://github.com/python/cpython/actions/runs/13396977667/job/37418372331?pr=130243
Ubuntu SSL tests with OpenSSL (ubuntu-24.04, 3.2.3) https://github.com/python/cpython/actions/runs/13396977667/job/37418373050?pr=130243
Ubuntu SSL tests with OpenSSL (ubuntu-24.04, 3.3.2) https://github.com/python/cpython/actions/runs/13396977667/job/37418373877?pr=130243
Ubuntu SSL tests with OpenSSL (ubuntu-24.04, 3.4.0) https://github.com/python/cpython/actions/runs/13396977667/job/37418374185?pr=130243
WASI / build and test https://github.com/python/cpython/actions/runs/13396977667/job/37418376040?pr=130243
Hypothesis tests on Ubuntu https://github.com/python/cpython/actions/runs/13396977667/job/37418372674?pr=130243
Address sanitizer (ubuntu-24.04) https://github.com/python/cpython/actions/runs/13396977667/job/37418371139?pr=130243
Thread sanitizer / Thread sanitizer https://github.com/python/cpython/actions/runs/13396977667/job/37418380002?pr=130243
Thread sanitizer (free-threading) / Thread sanitizer https://github.com/python/cpython/actions/runs/13396977667/job/37418379693?pr=130243
Cross build Linux https://github.com/python/cpython/actions/runs/13396977667/job/37418375242?pr=130243
CIFuzz https://github.com/python/cpython/actions/runs/13396977667/job/37418374880?pr=130243
All required checks pass https://github.com/python/cpython/actions/runs/13396977667/job/37419677250?pr=130243
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.