# List comprehension performance list_time = timeit.timeit( "[i * 2 for i in range(1000)]", number=100000 ) print(f"List comprehensions: list_time:.3fs")
async def main_new_way(): # Python 3.13 - same syntax, but ~10-15% faster # Task creation and scheduling overhead reduced async with asyncio.TaskGroup() as tg: tasks = [tg.create_task(process_item(i)) for i in range(1000)] return [task.result() for task in tasks] async def benchmark(): start = time.perf_counter() await main_old_way() old_time = time.perf_counter() - start python 3.13 changes
if sys.version_info < (3, 13): warnings.warn("Not running on Python 3.13", RuntimeWarning) return # List comprehension performance list_time = timeit
import sys import time from functools import lru_cache Run with: PYTHON_JIT=1 python script.py def fibonacci(n): """Classic recursive function - JIT helps here""" if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2) Decorators are faster @lru_cache(maxsize=None) def fibonacci_cached(n): if n <= 1: return n return fibonacci_cached(n-1) + fibonacci_cached(n-2) 13): warnings.warn("Not running on Python 3.13"
# Dictionary creation and access dict_setup = """ d = {} for i in range(1000): d[i] = i * 2 """