{"id":14235554,"url":"https://github.com/drujensen/fib","last_synced_at":"2025-05-14T20:06:27.736Z","repository":{"id":15781326,"uuid":"75239035","full_name":"drujensen/fib","owner":"drujensen","description":"Performance Benchmark of top Github languages","archived":false,"fork":false,"pushed_at":"2024-12-29T19:35:14.000Z","size":923,"stargazers_count":889,"open_issues_count":4,"forks_count":106,"subscribers_count":29,"default_branch":"main","last_synced_at":"2025-04-15T01:56:46.326Z","etag":null,"topics":["clang","cpp","crystal","csharp","dart","elixir","fibonacci-benchmark","go","java-8","javascript","julia","node","perl","php","python","python3","r","ruby","rust","swift"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/drujensen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-12-01T00:18:23.000Z","updated_at":"2025-04-11T02:03:12.000Z","dependencies_parsed_at":"2024-05-04T16:23:59.920Z","dependency_job_id":"b0ecf6e1-3a38-41fc-b4fa-e991b79dcd4a","html_url":"https://github.com/drujensen/fib","commit_stats":{"total_commits":296,"total_committers":67,"mean_commits":4.417910447761194,"dds":"0.45608108108108103","last_synced_commit":"e5eba2c1e8d8769b84eafabd5761e8a921f12fb1"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drujensen%2Ffib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drujensen%2Ffib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drujensen%2Ffib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drujensen%2Ffib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drujensen","download_url":"https://codeload.github.com/drujensen/fib/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248991544,"owners_count":21194894,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clang","cpp","crystal","csharp","dart","elixir","fibonacci-benchmark","go","java-8","javascript","julia","node","perl","php","python","python3","r","ruby","rust","swift"],"created_at":"2024-08-20T21:02:04.462Z","updated_at":"2025-04-15T01:56:53.845Z","avatar_url":"https://github.com/drujensen.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# Recursive Fibonacci Benchmark using top languages on Github\n\nTop 10: JavaScript, Python, Java, TypeScript, C#, Php, C++, C, Shell, Ruby [reference](https://octoverse.github.com)\n\nOthers: Go, Rust, Swift, Crystal, Pony, Ada, Pascal, Fortran, Kotlin, Clojure, Scala, Mono, R, Dart, Julia, D, Nim, Cython, Python3, PyPy, Ruby jit, OCaml, Lisp, Haskell, Erlang, Elixir, Escript, Dart, Scheme, Lua, Perl, Perl6, Bash, Emoji\n\nThe code performs a recursive fibonacci to the 47th position with the result of 2,971,215,073.\n\nFibonacci can be written many different ways.  The goal of this project is to compare how each language handles the exact same code.\n\nHere is the Ruby version:\n```\ndef fib(n)\n  return n if n \u003c= 1\n  fib(n - 1) + fib(n - 2)\nend\n\nputs fib(47)\n```\n\nHere is the Crystal version:\n```\ndef fib(n)\n  return n if n \u003c= 1\n  fib(n - 1) + fib(n - 2)\nend\n\nputs fib(47_u64)\n```\n\nTo keep a level playing field, only common \"release\" flags are used in the compilation step.  This allows for compiler optimizations like inlining and constant propogation but removes anything considered dangerous i.e. bypassing out of bounds checks.\n\nAll tests are run on:\n - Hetzner CCX23 - 4 vCPU\n - Processor: Intel Xeon 3.1Ghz\n - Memory: 16 GiB\n - OS: Ubuntu 24.04\n - Docker Base Image: ubuntu:24.04\n\n\n## How to run them\n\nYou can run the tests using Docker: `docker run -it drujensen/fib`\n\nBy default, it will compile and run all languages 5 times. Totals are calculated by adding the average compile and run times.\n\nTo only run a subset of the languages, provide a list of extensions and optionally the count:\n\n`docker run -it drujensen/fib ./run.sh s,c,cpp,go,rs,swift 5`\n\nTo run in the background using screen:\n\n```bash\nscreen\ndocker run drujensen/fib \u003e results.txt 2\u003e\u00261\n```\n\n- Detach from the session by pressing `Ctrl+A` followed by `D`.\n- You can reattach to the session later with:\n\n```bash\nscreen -r\n```\n\nNOTE: Please see [issues](https://github.com/drujensen/fib/issues) with benchmarks like this.  Its original goal was to compare at a macro level how much faster Crystal is to Ruby.  Any language faster than Assembly is performing unrolling type optimizations.  Modern languages like Go, Swift and Crystal have bounds checking which have safety built-in, but also have a cost associated with runtime performance.\n\n# Results\n\nLast benchmark was ran on December 05, 2024\n\n## Natively compiled, statically typed\n\n| Language | RunTime | Run | CompileTime | Compile | Ext |\n|----------|---------|-----|-------------|---------|-----|\n| C | 4.723 | ./fib | 0.112 | gcc -O3 -o fib fib.c | c |\n| C++ | 4.750 | ./fib | 0.139 | g++ -O3 -o fib fib.cpp | cpp |\n| V | 4.718 | ./fib | 4.450 | v -prod -o fib fib.v | v |\n| Fortran | 6.204 | ./fib | 0.130 | gfortran -O3 -o fib fib.f03 | f03 |\n| Ada | 6.591 | ./fib | 0.220 | gnat make -O3 -gnatp -o fib fib.adb | adb |\n| Rust | 7.750 | ./fib | 0.358 | rustc -C opt-level=3 fib.rs | rs |\n| Mojo | 8.706 | ./fib | 0.241 | mojo build fib.mojo | mojo |\n| Odin | 8.751 | ./fib | 0.087 | odin build fib.odin -file -0:speed | odin |\n| Zig | 9.299 | ./fib | 6.882 | zig build-exe -OReleaseFast ./fib.zig | zig |\n| Assembly | 9.342 | ./fib | 0.025 | gcc -no-pie -O3 -o fib fib.s | s |\n| Pony | 10.226 | ./fib | 0.879 | ponyc -s -b fib -p ./fib.pony | pony |\n| Pascal | 10.419 | ./fib | 0.041 | fpc -O3 -Si ./fib.pas | pas |\n| OCaml | 15.831 | ./fib | 0.187 | ocamlopt -O3 -o fib fib.ml | ml |\n| Swift | 17.390 | ./fib | 1.411 | swiftc -O fib.swift | swift |\n| Crystal | 17.420 | ./fib | 3.106 | crystal build --release fib.cr | cr |\n| Go | 17.842 | ./fib | 1.107 | go build fib.go | go |\n| D | 17.851 | ./fib | 0.342 | dmd -release -of=fib fib.d | d |\n| Haskell | 18.094 | ./fib | 0.001 | rm ./fib.o \u0026\u0026 ghc -O3 -o fib fib.hs | hs |\n| Lisp | 24.747 | ./fib | 0.979 | sbcl --load fib.lisp | lisp |\n| Dart Compiled | 30.149 | ./fib | 1.558 | dart compile exe -o fib ./fib.dart | dartc |\n| Cobol | 4380.596 | ./fib | 0.133 | cobc -x -O3 -o fib ./fib.cbl | cbl |\n\n## VM compiled bytecode, statically typed\n\n| Language | RunTime | Run | CompileTime | Compile | Ext |\n|----------|---------|-----|-------------|---------|-----|\n| C# | 10.744 | dotnet ./bin/fib.dll | 2.015 | dotnet build -c Release -o ./bin | cs |\n| Java | 12.307 | java Fib | 0.733 | javac Fib.java | java |\n| Kotlin | 12.212 | java FibKt | 4.074 | kotlinc Fib.kt | kt |\n| Scala | 13.153 | scala Fib | 2.682 | scalac Fib.scala | scala |\n| Erlang | 27.976 | erl -noinput -noshell -s fib | 0.402 | erlc +native +'{hipe,[o3]}' fib.erl | erl |\n| Groovy | 68.604 | groovy Fib | 1.519 | groovyc Fib.groovy | groovy |\n\n## VM compiled before execution, mixed/dynamically typed\n\n| Language | RunTime | Run | Ext |\n|----------|---------|-----|-----|\n| Clojure |   17.815 | clojure -M fib.cljc | cljc |\n| Julia |   18.000 | julia -O3 fib.jl | jl |\n| Bun |   21.312 | bun fib.js | bun |\n| Dart |   29.984 | dart fib.dart | dart |\n| Node |   34.736 | node fib.js | js |\n| Elixir |   35.243 | ERL_COMPILER_OPTIONS='[native,{hipe, [o3]}]' elixir Fib.exs | exs |\n| Lua Jit |   37.837 | luajit fib.lua | luajit |\n| Python (PyPy) |   54.078 | pypy fib.py | pypy |\n| Ruby (jit) |   81.454 | ruby --jit fib.rb | rbjit |\n\n## Interpreted, dynamically typed\n\n| Language | RunTime | Run | Ext |\n|----------|---------|-----|-----|\n| Escript |   28.380 | escript fib.es | es |\n| Scheme |  102.887 | guile fib.scm | scm |\n| Php |  157.312 | php fib.php | php |\n| Lua |  203.702 | lua fib.lua | lua |\n| Ruby |  393.625 | ruby fib.rb | rb |\n| Python | 423.427 | python fib.py | py |\n| Janet |  479.663 | janet ./fib.janet | janet |\n| Perl | 1490.416 | perl fib.pl | pl |\n| Raku | 1672.015 | rakudo fib.raku | raku |\n| Tcl | 2230.883 | tclsh fib.tcl | tcl |\n| R | 2575.249 | R -f fib.r | r |\n\n## Versions\nAll compilers are installed using apt or asdf on Ubuntu 24.04 docker image:\n\n|Language | Version |\n|---|---|\n| ada | 13.2.0 |\n| assembly | 13.2.0 |\n| bash | 5.2.21 |\n| bun | 1.1.38 |\n| crystal | 1.14.0 |\n| clojure | 1.12.0.1488 |\n| dart | 3.5.4 |\n| dmd | 2.109.1 |\n| dotnet | 9.0.101 |\n| elixir | 1.17.3 |\n| elm | 0.19.1 |\n| erlang | 27.1.2 |\n| fortran | 13.2.0 |\n| g++ | 13.2.0 |\n| gcc | 13.2.0 |\n| gnucobol | 3.2.0 |\n| golang | 1.23.2 |\n| groovy | 4.0.24 |\n| guile | 3.0.10 |\n| haskell | 9.8.3 |\n| janet | 1.36.0 |\n| java | openjdk-23 |\n| julia | 1.11.1 |\n| K | 3.6 |\n| kotlin | 2.1.0 |\n| ldc | 1.39.0 |\n| lua | 5.4.7 |\n| luajit | 2.1.1 |\n| mojo | 24.5.0 |\n| nim | 2.2.0 |\n| nodejs | 23.3.0 |\n| ocaml | 5.2.1 |\n| odin | dev-2024-11 |\n| pascal | 3.2.2 |\n| perl | 5.40.0 |\n| php | 8.4.1 |\n| pony | 0.58.7 |\n| powershell-core | 7.4.6 |\n| python | 3.12.0 |\n| pypy | 7.3.17 |\n| r | 4.4.2 |\n| rakudo | 2024.10 |\n| ruby | 3.3.6 |\n| rust | 1.83.0 |\n| sbcl | 2.4.11 |\n| scala | 3.3.4 |\n| swift | 6.0.2 |\n| tcl | 9.0.0 |\n| v | 0.4.8 |\n| zig | 0.13.0 |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrujensen%2Ffib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrujensen%2Ffib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrujensen%2Ffib/lists"}