Skip to content

Commit b66e761

Browse files
egedemircid1vyanshu
andcommitted
Update repo
Co-Authored-By: Divyanshu Bhardwaj <[email protected]>
1 parent 52029db commit b66e761

File tree

5 files changed

+158
-1
lines changed

5 files changed

+158
-1
lines changed

README.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,37 @@
11
# Performance-Comparison-of-Python-Runtime-Systems
2-
Performance Comparison of Python Runtime Systems: CPython, PyPy, and IronPython.
2+
This repository is codebase for Runtime Systems project. We implement and evaluate runtime and memory metrics for various benchmarks across three python interpreters - CPython3, PyPy3 and Jython.
3+
4+
## Set Up
5+
To setup and replicate our benchmark data, installing the same version of interpreters is necessary. To install, run
6+
7+
''' github clone link_to_the_repository
8+
cd path_to_repository
9+
chmod x+w setup.sh
10+
./setup.sh
11+
'''
12+
13+
## Recording runtime for benchmarks
14+
All the benchmarks are located in experiment/benchmarks directory. To run all the benchmarks and record runtime, run
15+
16+
'''
17+
python3 run_experiments.py
18+
'''
19+
20+
This would automatically run all benchmarks across all interpreters and store the runtimes in results.csv in the main directory.
21+
22+
## Memory Profiler Set Up
23+
We use memory_profiler which is the standard python memory profiling tool to collect memory usage statistics. Memory profiler has to be installed individually for each interpreters as follows:
24+
'''
25+
python3 -m pip install memory_profiler
26+
pypy3 -m pip install memory_profiler
27+
jython -m pip install memory_profiler
28+
'''
29+
30+
## Memory Profiling
31+
For each benchmark, run
32+
'''
33+
python3 -m mprof run benchmark.py
34+
mprof plot
35+
'''
36+
37+
This would produce a matplot with graph showing memory usage against runtime. Note: Plotting the graph requires matplotlib package.s

experiment/benchmarks/prime.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env python3
2+
3+
import time
4+
import json
5+
from memory_profiler import profile
6+
7+
def is_prime(n):
8+
"""
9+
Basic primality test with O(sqrt(n)) complexity.
10+
"""
11+
if n <= 1:
12+
return False
13+
if n <= 3:
14+
return True
15+
if n % 2 == 0 or n % 3 == 0:
16+
return False
17+
18+
i = 5
19+
while i * i <= n:
20+
if n % i == 0 or n % (i + 2) == 0:
21+
return False
22+
i += 6
23+
return True
24+
25+
@profile
26+
def prime_count(limit):
27+
"""
28+
Counts how many primes exist up to `limit`.
29+
"""
30+
count = 0
31+
for x in range(1, limit + 1):
32+
if is_prime(x):
33+
count += 1
34+
return count
35+
36+
def benchmark_cpu_intensive(limit=100000):
37+
"""
38+
A CPU-intensive benchmark that counts primes up to `limit`.
39+
Returns the number of primes found and the total runtime.
40+
"""
41+
start_time = time.time()
42+
total_primes = prime_count(limit)
43+
end_time = time.time()
44+
return total_primes, end_time - start_time
45+
46+
if __name__ == "__main__":
47+
limit = 5000000
48+
primes, runtime = benchmark_cpu_intensive(limit)
49+
50+
result = {
51+
"benchmark": "cpu_bound_prime_count",
52+
"limit": limit,
53+
"prime_count": primes,
54+
"runtime": runtime,
55+
"timestamp": time.time()
56+
}
57+
print(json.dumps(result))

github

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-----BEGIN OPENSSH PRIVATE KEY-----
2+
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
3+
QyNTUxOQAAACDgf6g3CO14/bc4p1PoP5j4KgkGbaLxWfL4gjmv2AqPGQAAAKDHUNNHx1DT
4+
RwAAAAtzc2gtZWQyNTUxOQAAACDgf6g3CO14/bc4p1PoP5j4KgkGbaLxWfL4gjmv2AqPGQ
5+
AAAEAbezo6SqfsJLVZMhb4pWng//CBmVyZGgT360oJZxFjTuB/qDcI7Xj9tzinU+g/mPgq
6+
CQZtovFZ8viCOa/YCo8ZAAAAHWQxdnlhYW5zaHUuYmhhcmR3YWpAZ21haWwuY29t
7+
-----END OPENSSH PRIVATE KEY-----

github.pub

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOB/qDcI7Xj9tzinU+g/mPgqCQZtovFZ8viCOa/YCo8Z [email protected]

setup.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
2+
3+
#!/bin/bash
4+
set -euo pipefail
5+
##Script for installing all three interpreters.
6+
# Update system and install dependencies
7+
sudo apt-get update -qq
8+
sudo apt-get install -qq -y software-properties-common wget
9+
10+
# Install Python 3
11+
if ! command -v python3 &> /dev/null; then
12+
echo "Installing Python 3..."
13+
sudo apt-get install -qq -y python3 python3-pip
14+
else
15+
echo "Python 3 already installed"
16+
fi
17+
18+
# Install PyPy3
19+
if ! command -v pypy3 &> /dev/null; then
20+
echo "Installing PyPy3..."
21+
sudo add-apt-repository -y universe
22+
sudo apt-get update -qq
23+
sudo apt-get install -qq -y pypy3 libssl-dev
24+
sudo ln -sf /usr/bin/pypy3 /usr/local/bin/pypy3
25+
else
26+
echo "PyPy3 already installed"
27+
fi
28+
29+
# Install Jython dependencies (Java)
30+
if ! command -v java &> /dev/null; then
31+
echo "Installing Java (Jython dependency)..."
32+
sudo apt-get install -qq -y openjdk-17-jdk
33+
else
34+
echo "Java already installed"
35+
fi
36+
37+
# Install Jython
38+
JYTHON_VERSION="2.7.3"
39+
JYTHON_DIR="/opt/jython"
40+
if ! command -v jython &> /dev/null; then
41+
echo "Installing Jython ${JYTHON_VERSION}..."
42+
sudo mkdir -p "${JYTHON_DIR}"
43+
sudo wget -q "https://repo1.maven.org/maven2/org/python/jython-installer/${JYTHON_VERSION}/jython-installer-${JYTHON_VERSION}.jar" -O /tmp/jython_installer.jar
44+
sudo java -jar /tmp/jython_installer.jar -s -d "${JYTHON_DIR}" -t standard
45+
sudo ln -sf "${JYTHON_DIR}/bin/jython" /usr/local/bin/jython
46+
sudo rm /tmp/jython_installer.jar
47+
else
48+
echo "Jython already installed"
49+
fi
50+
51+
# Verify installations
52+
echo -e "\nInstallation verification:"
53+
echo "Python 3: $(python3 --version 2>&1) [$(which python3)]"
54+
echo "PyPy3: $(pypy3 --version 2>&1) [$(which pypy3)]"
55+
echo "Jython: $(jython --version 2>&1) [$(which jython)]"
56+
57+
echo -e "\nInstallation completed successfully!"

0 commit comments

Comments
 (0)