Created
June 25, 2025 17:47
-
-
Save nascheme/189a3a32dd942c8d3c4c23e9fa62073c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # From https://github.com/python/cpython/issues/132917 | |
| import itertools | |
| import time | |
| def performance_test(n_options=5, n_items=5, iterations=50): | |
| list = [] | |
| def expensive_operation(): | |
| # Create lists of tuples | |
| data = [] | |
| for _ in range(n_options): | |
| data.append([(f"a{i}", f"b{i}") for i in range(n_items)]) | |
| # Generate all combinations and create result tuples | |
| results = [] | |
| for combo in itertools.product(*data): | |
| result = tuple((x[0], x[1], f"name_{i}") for i, x in enumerate(combo)) | |
| results.append(result) | |
| # Commenting the following line solves the performance regression in free-threaded mode | |
| list.append(results) | |
| return results | |
| start = time.time() | |
| for _ in range(iterations): | |
| result = expensive_operation() | |
| duration = time.time() - start | |
| print(f"n_options={n_options}, n_items={n_items}, iterations={iterations}") | |
| print(f"Time: {duration:.4f}s, Combinations: {len(result)}") | |
| return duration | |
| if __name__ == "__main__": | |
| print("Python Performance Regression Test") | |
| print("-" * 40) | |
| performance_test() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment