An open API service indexing awesome lists of open source software.

https://github.com/lucascompython/speed-comparison

This project compares the speed of different languages.
https://github.com/lucascompython/speed-comparison

benchmark cpp csharp deno dotnet golang java javascript lua php powershell programming-languages python ruby rust sieve-of-eratosthenes speed speed-comparison typescript

Last synced: 15 days ago
JSON representation

This project compares the speed of different languages.

Awesome Lists containing this project

README

          

# Speed comparison of programming languages

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.

---

# Preview

![plot](https://cdn.discordapp.com/attachments/795277227423301643/978406323182002236/Results.png "Speed comparison of programming languages")
![table](https://cdn.discordapp.com/attachments/795277227423301643/980566875064905748/unknown.png "Table")

![lines](https://img.shields.io/tokei/lines/github/lucascompython/speed-comparison)



contributors


last update


forks


stars


open issues


license

[See more](All_Results_Preview.md)

---

## Methods

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.

```python
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](https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes) in Python

```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
```

## Disclaimer

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](#known-bugs-because-im-too-lazy-to-fix-them).

The results shown in [preview](#preview) may vary A LOT because im running this tests on a potato :(

## Languages used in this comparison

In total there are available 14 languages in this comparison which are:

- [Python](https://www.python.org/) - interpreted
- [C++](https://isocpp.org/) - compiled
- [JavaScript](https://www.ecma-international.org/publications-and-standards/standards/ecma-402/) using [Node](https://nodejs.org/en/) - interpreted; JIT
- [TypeScript](https://www.typescriptlang.org) using [Deno](https://deno.land) - interpreted; JIT
- [Java](http://www.oracle.com/technetwork/java/index.html) - compiled, VM
- [C#](https://docs.microsoft.com/en-us/dotnet/csharp/) - compiled
- [Lua](https://www.lua.org) - interpreted, JIT
- [PHP](https://www.php.net) - interpreted, JIT
- [Ruby](www.ruby-lang.org) - interpreted
- [Go](https://golang.org/) - compiled
- [Rust](https://www.rust-lang.org/) - compiled
- [Powershell](https://docs.microsoft.com/en-us/powershell/) - interpreted
- [Swift](https://www.swift.org) - interpreted / compiled
- [Dart](https://dart.dev) - compiled, JIT

## Features

- 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.

## Run it yourself

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](https://matplotlib.org).
Everything can be ran inside a Docker container.

### Requirements

- `Docker`
- `Makefile` support

### Instalation and Execution

```bash
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
```

## FAQ

> 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.

## TODO (Mostly by Order)

- [X] Add TypeScript with [Deno](https://deno.land)
- [X] Add JavaScript with [Node](https://nodejs.org)
- [X] Add Java
- [X] Finish adding an optimized version for each language using compiler optimizations and using the [Sieve of Eratosthenes](https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes)
- [X] Add an option to run the comparisons in parallel
- [X] Add an option to run natively
- [X] Add C#
- [X] Add Lua
- [X] Add Php
- [X] Add Ruby
- [X] Add Golang
- [X] Add Rust
- [X] Add Terminal graphs
- [X] Add Powershell
- [X] Add Swift
- [X] Add Dart
- [X] 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 π](https://en.wikipedia.org/wiki/Leibniz_formula_for_%CF%80) 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...

## Known Bugs (Because im too lazy to fix them...)

* 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 :shushing_face:

1. **Most** languages are good, use whatever you want.
2. Execpt HTML
3. Fuck HTML