Last active
August 29, 2015 14:02
-
-
Save maarek/1a86a1ed7c0094d84a31 to your computer and use it in GitHub Desktop.
elixir --erl "+P 1000000" bigchain.exs
This file contains hidden or 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 Bigchain do | |
def start(n) do | |
start self, n | |
end | |
def start(pid, 0) do | |
#IO.puts "start #{inspect pid}, 0" | |
send pid, {:stop, 0} | |
end | |
def start(pid, n) do | |
s = self | |
#IO.puts "start #{inspect s}, #{n}" | |
spawn_link fn -> start s, n-1 end | |
loop pid | |
end | |
def loop(pid) do | |
#IO.puts "loop #{inspect pid}" | |
receive do | |
{:stop, n} -> send pid, {:stop, n+1} | |
{_} -> loop pid | |
end | |
end | |
end | |
{us, _} = :timer.tc(fn -> Bigchain.start 1_000_000 end) | |
IO.puts "#{Float.round(us / 1000000, 2)} seconds" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment