Title: Generator finalization is slower in 3.11 vs 3.10 · Issue #100762 · python/cpython · GitHub
Open Graph Title: Generator finalization is slower in 3.11 vs 3.10 · Issue #100762 · python/cpython
X Title: Generator finalization is slower in 3.11 vs 3.10 · Issue #100762 · python/cpython
Description: I found that the Python 3.11.1 implementation of all() is 30% slower compared to Python 3.10.9. any() also seems to be around 4% slower on my device Environment CPython versions tested on: Python 3.10.9 and Python 3.11.1 Operating system...
Open Graph Description: I found that the Python 3.11.1 implementation of all() is 30% slower compared to Python 3.10.9. any() also seems to be around 4% slower on my device Environment CPython versions tested on: Python 3...
X Description: I found that the Python 3.11.1 implementation of all() is 30% slower compared to Python 3.10.9. any() also seems to be around 4% slower on my device Environment CPython versions tested on: Python 3...
Opengraph URL: https://github.com/python/cpython/issues/100762
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Generator finalization is slower in 3.11 vs 3.10","articleBody":"I found that the Python 3.11.1 implementation of all() is 30% slower compared to Python 3.10.9.\r\n\r\nany() also seems to be around 4% slower on my device\r\n\r\n# Environment\r\n- CPython versions tested on: Python 3.10.9 and Python 3.11.1\r\n- Operating system and architecture: Windows 10 22H2 (Build 19045) 64 bit\r\n\r\n# Code to test all():\r\n```python \r\nimport timeit\r\nfrom functools import partial\r\nimport platform\r\n\r\n\r\ndef find_by_keys(\r\n keys: list[str],\r\n table: list[dict[str, str | int]],\r\n match_data: dict[str, str | int],\r\n) -\u003e dict[str, str | int] | None:\r\n for item in table:\r\n if all(item[k] == match_data[k] for k in keys):\r\n return item\r\n return None\r\n\r\n\r\ndef main():\r\n keys: list[str] = [\"id\", \"key_1\", \"key_2\"]\r\n table: list[dict[str, str | int]] = [\r\n {\r\n \"id\": i,\r\n \"key_1\": \"val_1\",\r\n \"key_2\": \"val_2\",\r\n }\r\n for i in range(1, 5001)\r\n ]\r\n match_data: dict[str, str | int] = {\r\n \"id\": 3000,\r\n \"key_1\": \"val_1\",\r\n \"key_2\": \"val_2\",\r\n }\r\n\r\n timeit_output = timeit.repeat(\r\n partial(find_by_keys, keys, table, match_data), repeat=10000, number=1\r\n )\r\n\r\n average_time = sum(timeit_output) / len(timeit_output)\r\n best_time = min(timeit_output)\r\n tps_output = 1 / average_time\r\n\r\n print(f\"Python version = {platform.python_version()}\")\r\n print(f\"Average time = {average_time}\")\r\n print(f\"Best time = {best_time}\")\r\n print(f\"Average transactions per second = {tps_output}\")\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n\r\n```\r\n \r\n# Results for all()\r\n\r\nConsole output using Python 3.10.9:\r\n```\r\nPython version = 3.10.9\r\nAverage time = 0.0008256170657486655\r\nBest time = 0.0007106999401003122\r\nAverage transactions per second = 1211.2152733824669\r\n```\r\n\r\nConsole output using Python 3.11.1:\r\n```\r\nPython version = 3.11.1\r\nAverage time = 0.0011819988898839802\r\nBest time = 0.001033599954098463\r\nAverage transactions per second = 846.0244832363215\r\n```\r\n\r\n\r\n# Code to test any():\r\n```python \r\nimport timeit\r\nfrom functools import partial\r\nimport platform\r\n\r\n\r\ndef find_by_keys(\r\n keys: list[str],\r\n table: list[dict[str, str | int]],\r\n match_data: dict[str, str | int],\r\n) -\u003e dict[str, str | int] | None:\r\n for item in table:\r\n if any(item[k] == match_data[k] for k in keys):\r\n return item\r\n return None\r\n\r\n\r\ndef main():\r\n keys: list[str] = [\"id\", \"key_1\", \"key_2\"]\r\n table: list[dict[str, str | int]] = [\r\n {\r\n \"id\": i,\r\n \"key_1\": \"foo_1\",\r\n \"key_2\": \"foo_2\",\r\n }\r\n for i in range(1, 5001)\r\n ]\r\n match_data: dict[str, str | int] = {\r\n \"id\": 3000,\r\n \"key_1\": \"val_1\",\r\n \"key_2\": \"val_2\",\r\n }\r\n\r\n timeit_output = timeit.repeat(\r\n partial(find_by_keys, keys, table, match_data), repeat=10000, number=1\r\n )\r\n\r\n average_time = sum(timeit_output) / len(timeit_output)\r\n best_time = min(timeit_output)\r\n tps_output = 1 / average_time\r\n\r\n print(f\"Python version = {platform.python_version()}\")\r\n print(f\"Average time = {average_time}\")\r\n print(f\"Best time = {best_time}\")\r\n print(f\"Average transactions per second = {tps_output}\")\r\n\r\n\r\nif __name__ == \"__main__\":\r\n main()\r\n\r\n```\r\n \r\n# Results for any()\r\n\r\nConsole output using Python 3.10.9:\r\n```\r\nPython version = 3.10.9\r\nAverage time = 0.0009300541202770546\r\nBest time = 0.00090230000205338\r\nAverage transactions per second = 1075.206246817238\r\n```\r\n\r\nConsole output using Python 3.11.1:\r\n```\r\nPython version = 3.11.1\r\nAverage time = 0.0009645268900785595\r\nBest time = 0.000930099980905652\r\nAverage transactions per second = 1036.7777303943815\r\n```\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-101011\n* gh-101013\n* gh-101316\n* gh-111069\n* gh-115818\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/Onlooker2186","@type":"Person","name":"Onlooker2186"},"datePublished":"2023-01-05T00:02:06.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":31},"url":"https://github.com/100762/cpython/issues/100762"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:7edab5f8-c33e-113a-6d58-17bc9264030a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8A94:39E51F:31E2AE7:4144013:696B8A9A |
| html-safe-nonce | 8e4f1e2d4bde9edd899a8b0d3e49fdbffe43ec934ea15e2e83b0a55da9b24d10 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QTk0OjM5RTUxRjozMUUyQUU3OjQxNDQwMTM6Njk2QjhBOUEiLCJ2aXNpdG9yX2lkIjoiMjgwNTQ2OTY3MTY5MzQ1Mzk3OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 5e927ff230955465bd1d83bb9474d80f7ba06ea6a3403053ab34dceaf8166c18 |
| hovercard-subject-tag | issue:1519758243 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/100762/issue_layout |
| twitter:image | https://opengraph.githubassets.com/48fd6417af3a4ae18a2f7c37e79db3f8f9008e9c45e985b7ee304aa0e5dc4965/python/cpython/issues/100762 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/48fd6417af3a4ae18a2f7c37e79db3f8f9008e9c45e985b7ee304aa0e5dc4965/python/cpython/issues/100762 |
| og:image:alt | I found that the Python 3.11.1 implementation of all() is 30% slower compared to Python 3.10.9. any() also seems to be around 4% slower on my device Environment CPython versions tested on: Python 3... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Onlooker2186 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5f99f7c1d70f01da5b93e5ca90303359738944d8ab470e396496262c66e60b8d |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 82560a55c6b2054555076f46e683151ee28a19bc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width