This projects tries to compare the speed of different programming languages. In this project we don't really care about getting a precise calculation of pi. We only want to see how fast are the programming languages doing.
It uses an implementation of the Leibniz formula for π to do the comparison.
Here is a video which explains how it works: Calculating π by hand
I'm no expert in all these languages, so take my results with a grain of salt.
Also the findings just show how good the languages can handle floating point operations, which is only one aspect of a programming language.
You are also welcome to contribute and help me fix my possible horrible code in some languages. 😄
- C - compiled
- C++ - compiled
- Crystal - compiled
- Elixir - compiled
- Go - compiled
- Java - compiled, VM
- Julia - JIT
- Javascript using Node.js - interpreted, JIT
- Lua - interpreted
- Nim - compiled
- PHP - interpreted
- Python - interpreted (CPython)
- R - interpreted
- Ruby - interpreted
- Rust - compiled
- Swift - compiled (in this test interpreted due to Linux Swift limitations)
2022-10-02_22:18
: csv | png2018-03-02_01:26
: csv | png2018-03-02_01:14
: csv | png2018-03-02_00:08
: csv | png2018-02-27
: csv | png2018-02-26
: csv | png
Everything is run by a Docker container and a bash script which envokes the programs.
To measure the execution time a python package is used.
Docker
- earthly
Earthly allows to run everything with a single command:
earthly --config earthly-config.yml +all
This will run all tasks to collect all measurements and then run the analysis.
To collect data for all languages run:
earthly --config earthly-config.yml +collect-data
To collect data for a single languages run:
earthly --config earthly-config.yml +<replace me with language name>
To generate the combined CSV out of all results use this command:
earthly --config earthly-config.yml +analysis
Why do you also count reading a file and printing the output?
Because I think this is a more realistic scenario to compare speeds.
Are the compile times included in the measurements?
No they are not included, because when running the program in the real world this would also be done before.
- Add C++
- Add run pypy for Python
- Produce graphic with results
- Add Java
- Add Swift
- Add R
- Add Elixir
- Add Smalltalk
- Add C#
- Add Perl
- Add Kotlin
- Add Haskell
- Add Lisp
- Add Ada
- Add COBOL
Thanks to all the lovely contributors:
(Please feel free to add yourself to the list.)
The scbench
tool uses the great application bench from Shravan-1908 as a basis. Thank you very much for creating this tool!
This projects takes inspiration from Thomas who did a similar comparison on his blog.