Professional Documents
Culture Documents
Project Memory Efficiency of Rust Design
Project Memory Efficiency of Rust Design
Professor:
Tamás Kovácsházy
BUDAPEST, 2023
Project Description
The goal of this project is to learn about memory efficiency properties of Rust
programming language by making comparisons of the programs that are written
in Rust and Python. Raspberry Pi 2 will be used to run programs, because we
want to test our project in a real hardware. To check the efficiency, execution
time and memory capacity will be considered in this project.
Rust and Python are two programming languages that have distinct differences
in terms of their design philosophies, performance characteristics, and areas of
application. Here are some key differences between Rust and Python:
1. Performance: - Rust is a statically typed, compiled language that emphasizes
performance and memory safety. It achieves this through features like strict
ownership and borrowing rules, which enable efficient memory management
and eliminate common bugs like null pointer dereferences and data races.
Python, on the other hand, is an interpreted language known for its simplicity
and ease of use but generally has a slower execution speed compared to Rust.
2. Type System: Rust has a strong static type of system that enforces strict
compile-time type checking. It uses type inference to determine types wherever
possible but requires explicit type annotations in certain cases. Python, on the
other hand, is dynamically typed, which means that variable types are
determined at runtime. Python allows for flexible and dynamic programming
but can lead to certain types of runtime errors that would be caught during
compilation in Rust.
3. Concurrency and Parallelism: Rust provides powerful features for safe
concurrency and parallelism. Its ownership and borrowing system allow for
fine-grained control over mutable data access, making it easier to write
concurrent and thread-safe code. Python, on the other hand, has a Global
Interpreter Lock (GIL) that prevents true parallel execution of threads, limiting
its ability to fully utilize multi-core processors for CPU-bound tasks. However,
Python offers high-level abstractions and libraries for asynchronous
programming, making it suitable for I/O-bound applications.
4. Ecosystem and Libraries: - Python has a vast and mature ecosystem with a
wide range of libraries and frameworks for various domains, including web
development, data analysis, machine learning, and more. Rust's ecosystem is
growing rapidly, but it is still relatively young compared to Python. Rust excels
in areas where high-performance and system-level programming are required,
such as network programming, systems development, and low-level hardware
interactions.
5. Ease of Use: Python is often praised for its simplicity and readability. Its
syntax is designed to be human-friendly, making it easy to write and understand
code. Rust, while it has a steeper learning curve, provides advanced features
and expressive syntax that gives developers fine-grained control and enables
writing highly performant and safe code.
Methodology
To start the PuTTY connection, these settings must be configured:
Figure 2. Connecting To raspberry Pi with windows laptop
Results
1) Calculating the Value of Pi
In order to calculate the value of Pi, pi.py and py.rs files are used. The graph below
illustrates CPU Power occupation in Y axis and execution time in X axis. From the
graph, we can see that, Rust is 86% efficient in terms of CPU power occupation.
4) Matrix Multiplications
In order to do matrix operations, matrix.py and matrix.rs files are used. In this case Rust
was 84.79% faster than Python:
In the below figure, we can see some standard library functions and how much
execution time they occupy.
Figure 5. SDL Functions and their execution time in Raspberry Pi.