Skip to content

sunny-mittal/fibonacci

Repository files navigation

Fibonacci

This is a simple repo containing functions that calculate the nth Fibonacci number in several different languages to demonstrate syntax differences and approximations of running times. I'm by no means fluent in these languages, so it's very possible and highly probable that my code will be sub-optimal in some cases.

Note: Values of 0 indicate inability to accurately time.

Results

Recursive (40th fib number)

  • C: 685 ms
  • C++: 660 ms
  • Clojure: 0.439 ms
  • CoffeeScript: 1262 ms
  • Crystal: 631 ms
  • Dart: 508 ms
  • Erlang: 2222 ms
  • Elixir: 2864 ms
  • Go: 635 ms
  • Haskell: 3693 ms
  • Java: 358 ms
  • JavaScript: 1241 ms
  • LiveScript: 1203 ms
  • Python: 38419 ms
  • PyPy: 3313 ms // same code as for python...pretty amazing
  • Ruby: 12877 ms
  • Rust: 1311 ms
  • SML : 526 ms
  • Swift: 695 ms

Iterative (100th fib number calculated 10 times in case integer overflow makes calculations simpler (I don't know, and if this is contributing even more error, please let me know!))

  • C: 0.004 ms
  • C++: 0.005 ms
  • CoffeeScript: 0.200 ms
  • Crystal: 0.453 ms
  • Dart: 1 ms
  • Elixir: 267 ms
  • Go: 0.020 ms
  • Java: 0 ms
  • JavaScript: 0.494 ms
  • LiveScript: 0.143 ms
  • Python: 0.095 ms
  • PyPy: 0.768 ms
  • Ruby: 0.230 ms
  • Rust: 0 ms
  • Swift: 154 ms

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published