🚀 Exploring Python Without the GIL! 🚀
This repository benchmarks the performance of Python 3.13.1 with and without the Global Interpreter Lock (GIL) using real-world workloads.
📖 Read the full analysis and benchmark results in my blog post:
👉 Exploring Python 3.13: Hands-on with the GIL Disablement
docker build --no-cache --file python-3.13.1-bookworm-gil.Dockerfile --tag python:3.13.1-bookworm-gil .
docker build --no-cache --file python-3.13.1-bookworm-nogil.Dockerfile --tag python:3.13.1-bookworm-nogil .
This section verifies whether the Global Interpreter Lock (GIL) is enabled or disabled in the Python environment. Running gil_status.py
will confirm if the GIL is active, ensuring the correct interpreter settings before executing performance benchmarks.
Run gil_status.py
to verify that the GIL is active:
docker container run --rm -it -v ${pwd}/src:/app -w /app python:3.13.1-bookworm-gil python gil_status.py
Run gil_status.py
to verify that the GIL is disabled:
docker container run --rm -it -v ${pwd}/src:/app -w /app python:3.13.1-bookworm-nogil python gil_status.py
This benchmark tests a CPU-intensive mathematical computation by counting prime numbers within a given range. The test is executed in both single-threaded and multi-threaded modes to measure the impact of the GIL on parallel performance.
Run prime_counter.py
to measure the performance of prime number calculations in Python 3.13.1 with the GIL:
docker container run --rm -it -v ${pwd}/src:/app -w /app python:3.13.1-bookworm-gil python prime_counter.py
Run prime_counter.py
to measure the performance of prime number calculations in Python 3.13.1 with the GIL disabled:
docker container run --rm -it -v ${pwd}/src:/app -w /app python:3.13.1-bookworm-nogil python prime_counter.py
This benchmark simulates a real-world financial workload by analyzing loan applications and calculating a risk score for each applicant. The dataset is processed in both single-threaded and multi-threaded modes to compare performance with and without the GIL.
Run loan_risk_scoring_benchmark.py
to measure the performance of risk scoring in Python 3.13.1 with the GIL:
docker container run --rm -it -v ${pwd}/src:/app -v ${pwd}/data:/data -w /app python:3.13.1-bookworm-gil python loan_risk_scoring_benchmark.py
Run loan_risk_scoring_benchmark.py
to measure the performance of risk scoring in Python 3.13.1 with the GIL disabled:
docker container run --rm -it -v ${pwd}/src:/app -v ${pwd}/data:/data -w /app -e PYTHON_GIL=0 python:3.13.1-bookworm-nogil python loan_risk_scoring_benchmark.py