This project compares the speed and memory of different programming/scripting languages.
It calculates prime and composite numbers with a very basic algorithm and an more advanced one, from any given interval to do this comparisom.
All languages use the same algorithms.
The code below is a Python code snippet of the not optimal but not bad algorithm used for counting prime and composite numbers to a given range, that is used for the different languages.
for num in range(rounds):
ctr = 0
for i in range(2, num // 2):
if num % i == 0:
ctr += 1
composites += 1
break
if ctr == 0 and num != 1:
primes += 1
The code below is an implemation of the Sieve of Eratosthenes in Python
primes = [True for _ in range(rounds + 1)]
for i in range(2, round(sqrt(rounds)) + 1):
if primes[i]:
for j in range(i ** 2, rounds, i):
primes[j] = False
total = 0
for k in range(2, rounds):
if primes[k]:
total += 1
composites = rounds - total
I'm no expert in all these languages, so take my results with a grain of salt.
The speed of the language does not determine its quality.
You are also more than welcome to contribute and help me.
See Known Bugs.
The results shown in preview may vary A LOT because im running this tests on a potato :(
In total there are available 14 languages in this comparison which are:
- Python - interpreted
- C++ - compiled
- JavaScript using Node - interpreted; JIT
- TypeScript using Deno - interpreted; JIT
- Java - compiled, VM
- C# - compiled
- Lua - interpreted, JIT
- PHP - interpreted, JIT
- Ruby - interpreted
- Go - compiled
- Rust - compiled
- Powershell - interpreted
- Swift - interpreted / compiled
- Dart - compiled, JIT
- Graphs
- Tables
- Advanced but simple command line integration with multiple options for comparing (E.g: choosing with languages to compare and changing the values of the iterations).
- All languages will read from a txt file.
- The program will get and display the memory usage.
- It also has two modes, one for running native and other for running inside a docker container.
- Can choose to run in sequence or in parallel.
- Saves results in various formats.
To measure the execution time, in each language is implemented a timer. To measure the compilation / interpretation time and peak memory usage, before each measurement the GNU time command is invoked. The plots are made with MatPlotLib. Everything can be ran inside a Docker container.
Docker
Makefile
support
git clone https://github.com/lucascompython/speed-comparison.git
cd speed-comparison
make run-native #to run natively must have all requirements, to run inside docker use make build && make run-docker
Does it work on Windows?
Yes, I think...
Are the compile/interpret times included in the comparison?
Yes, it's measured by the GNU time command!
Why do you also count reading a file and printing the ouput?
Because I think this is a more realistic scenario to compare speeds.
- Add TypeScript with Deno
- Add JavaScript with Node
- Add Java
- Finish adding an optimized version for each language using compiler optimizations and using the Sieve of Eratosthenes
- Add an option to run the comparisons in parallel
- Add an option to run natively
- Add C#
- Add Lua
- Add Php
- Add Ruby
- Add Golang
- Add Rust
- Add Terminal graphs
- Add Powershell
- Add Swift
- Add Dart
- Add the ability to run the comparison multiple times and then show the mean, best and worst time.
- Add Bash
- Add Zig
- Add Julia
- Add V
- Add other methods of comparing E.g: Leibniz formula for π to compare the floating point operations
- Add full Docker Support
- Add Kotlin
- Add F#
- Add Haskell
- Add Scala
- Add Nix
- Add R
- Add R plots instead of MatPlotLib
- Add Elixir
- Add Raku (Perl6)
- Add Nim
- And many others...
- For the first time running the comparison you might need to to run it twice because deno shows some extra information at the first compilation of a file.
- Docker doesn't support graphical graphs for now.
Super top Secret 🤫
- Most languages are good, use whatever you want.
- Execpt HTML
- Fuck HTML