Skip to content

Instantly share code, notes, and snippets.

@maarek
Last active August 29, 2015 14:02
Show Gist options
  • Save maarek/1a86a1ed7c0094d84a31 to your computer and use it in GitHub Desktop.
Save maarek/1a86a1ed7c0094d84a31 to your computer and use it in GitHub Desktop.
elixir --erl "+P 1000000" bigchain.exs
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