https://github.com/abarrak/why-compiled-languages
A simple experiment for compiled/dynamic languages comparision.
https://github.com/abarrak/why-compiled-languages
cpp csharp go java javascript python ruby
Last synced: 11 months ago
JSON representation
A simple experiment for compiled/dynamic languages comparision.
- Host: GitHub
- URL: https://github.com/abarrak/why-compiled-languages
- Owner: abarrak
- License: mit
- Created: 2021-12-25T14:08:32.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-11-15T18:03:08.000Z (over 1 year ago)
- Last Synced: 2025-05-13T01:47:32.844Z (11 months ago)
- Topics: cpp, csharp, go, java, javascript, python, ruby
- Language: C#
- Homepage: https://whycompiledlanguages.com/
- Size: 340 KB
- Stars: 7
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Why Compiled Languages?
This is a very simple experiment to demonstrate the importance of compiled languages over dynamic or interpreted languages when it comes to system programming or high degree of efficiency.
## Experiment
A simple loop operation to sum up the numbers from 1 to 1,000,000,000 (one billion).
## Execution
Clone the repo, then open `src/` directory.
C++ run:
```shell
$ g++ cplusplus.cpp -o cpp -O3
$ ./cpp
```
Java run:
```shell
$ javac java.java
$ java Java
```
C# run:
_Note: use `mono` on macOS/linux only._
```shell
$ csc csharp.cs
$ mono csharp.exe
```
Python run:
```shell
$ python python.py
```
Ruby run:
```shell
$ ruby ruby.rb
```
Javascript (node) run:
```javascript
$ node javascript.js
```
Go run:
```shell
$ go build go.go
$ ./go
```
## Evaluation
To obtain the time spent on execution, measure the last line of each run with `time` multiple times and get the average.
For example:
```shell
$ time java Java
...
real 0m0.395s
user 0m0.361s
sys 0m0.028s
$ /usr/bin/time -l java Java
...
22679552 maximum resident set size
```
## Results
Results breakdown (macOS mid 2015, 2.5 GHz Quad-Core Intel Core i7, 16 GB RAM):
| Language | Elapsed Time (second) | Memory (MB) |
| ----------- | --------------------- | ----------- |
| C++ | 0.015 | 7.49 |
| Java | 0.39 | 23 |
| C# | 1.172 | 11.88 |
| Ruby | 21.77 | 13.45 |
| Python | 17.89 | 4.66 |
| JS (node) | 0.873 | 22.97 |
| Go | 0.284 | 1.56 |
Clearly, the way of optimization of this pure calculation logic in compiled versions as we see in static compiled languages outperformed the interperted languages (except `nodeJs`) drastically in terms of speed. Additionally, `Java` and `C#` results show the outstanding optimization made to the compiler and runtime `JVM`/`CLR` to perform nearly identical to the low level languages, for such essential looping computing.
The two figures below show the comparison between `C++`, `C#`, `Java`, `Ruby`, and `Python` languages in terms of both speed (time) and memory (space).
## Contribution
All PRs are welcome for other languages or improvements [on Github](https://github.com/abarrak/why-compiled-languages).
## License
MIT.
## Contributors
- Abdullah Barrak [(@abarrak)](https://github.com/abarrak).
- Eliot Akira [(@eliot-akira)](https://github.com/eliot-akira).