Elixir: first look
I don't have a clear impression about Elixir language yet. I don't like it has Ruby like syntax, but do like it has pipe operator and macros. So, Fibonacci:
It executes in about 13 seconds which is on pair (even faster for unknown reason) with Erlang, no surprises here.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Fib do | |
def fib(0), do: 0 | |
def fib(1), do: 1 | |
def fib(n), do: fib(n-1) + fib(n-2) | |
end | |
defmodule Test do | |
def tc(f), do: :timer.tc(f) |> elem(0) |> Kernel./1_000 | |
def run(n), do: | |
tc (fn -> | |
for x <- 0..n, do: | |
IO.puts "Fib(#{x}) = #{Fib.fib(x)}" | |
end) | |
end |
- D (GDC) - 0.990
- C# - 1.26
- D (DMD) - 1.3
- C++ - 1.33
- F# - 1.38
- Nemerle - 1.45
- Rust - 1.66
- Go - 2.38
- Haskell - 2.8
- Clojure - 9
- Elixir - 13
- Erlang - 17
- Ruby - 60
- Python - 120
Comments