Skip to content
This repository was archived by the owner on Apr 11, 2019. It is now read-only.

Commit 661d382

Browse files
author
José Valim
committed
Add bench directory
1 parent 324c28e commit 661d382

File tree

6 files changed

+80
-2
lines changed

6 files changed

+80
-2
lines changed

bench/erlang.exs

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# MIX_ENV=bench mix run bench/erlang.exs
2+
# TASKS=8 MIX_ENV=bench mix run bench/erlang.exs
3+
4+
Code.require_file "shared.exs", __DIR__
5+
6+
defmodule ErlangRegistry do
7+
def whereis_name(name) do
8+
:erlang.whereis(name)
9+
end
10+
11+
def register_name(name, pid) when pid == self() do
12+
:erlang.register(name, pid)
13+
:yes
14+
end
15+
end
16+
17+
tasks = String.to_integer System.get_env("TASKS") || "1"
18+
19+
names =
20+
for task <- 1..tasks do
21+
for i <- 1..10000, do: :"name-#{task}-#{i}"
22+
end
23+
24+
:timer.tc(fn ->
25+
names
26+
|> Enum.map(&Task.async(Shared, :register, [&1]))
27+
|> Enum.each(&Task.await(&1, :infinity))
28+
end) |> IO.inspect

bench/gproc.exs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# MIX_ENV=bench mix run bench/erlang.exs
2+
# TASKS=8 MIX_ENV=bench mix run bench/erlang.exs
3+
4+
Code.require_file "shared.exs", __DIR__
5+
Application.ensure_all_started(:gproc)
6+
7+
tasks = String.to_integer System.get_env("TASKS") || "1"
8+
9+
names =
10+
for task <- 1..tasks do
11+
for i <- 1..10000, do: {:via, :gproc, {:n, :l, {task, i}}}
12+
end
13+
14+
:timer.tc(fn ->
15+
names
16+
|> Enum.map(&Task.async(Shared, :register, [&1]))
17+
|> Enum.each(&Task.await(&1, :infinity))
18+
end) |> IO.inspect

bench/registry.exs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# MIX_ENV=bench mix run bench/erlang.exs
2+
# TASKS=8 MIX_ENV=bench mix run bench/erlang.exs
3+
# PARTITIONS=8 TASKS=8 MIX_ENV=bench mix run bench/erlang.exs
4+
5+
Code.require_file "shared.exs", __DIR__
6+
partitions = String.to_integer System.get_env("PARTITIONS") || "1"
7+
Registry.start_link(:unique, Registry, partitions: partitions)
8+
9+
tasks = String.to_integer System.get_env("TASKS") || "1"
10+
11+
names =
12+
for task <- 1..tasks do
13+
for i <- 1..10000, do: {:via, Registry, {Registry, {task, i}}}
14+
end
15+
16+
:timer.tc(fn ->
17+
names
18+
|> Enum.map(&Task.async(Shared, :register, [&1]))
19+
|> Enum.each(&Task.await(&1, :infinity))
20+
end) |> IO.inspect

bench/shared.exs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
defmodule Shared do
2+
@compile :inline_list_funcs
3+
4+
def register(names) do
5+
:lists.foreach(fn name ->
6+
Agent.start_link(fn -> [] end, name: name)
7+
end, names)
8+
:ok
9+
end
10+
end

mix.exs

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ defmodule Registry.Mixfile do
3333
#
3434
# Type "mix help deps" for more examples and options
3535
defp deps do
36-
[{:ex_doc, "~> 0.14", only: :docs}]
36+
[{:ex_doc, "~> 0.14", only: :docs},
37+
{:gproc, "~> 0.6", only: :bench}]
3738
end
3839
end

mix.lock

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
%{"earmark": {:hex, :earmark, "1.0.2", "a0b0904d74ecc14da8bd2e6e0248e1a409a2bc91aade75fcf428125603de3853", [:mix], []},
2-
"ex_doc": {:hex, :ex_doc, "0.14.3", "e61cec6cf9731d7d23d254266ab06ac1decbb7651c3d1568402ec535d387b6f7", [:mix], [{:earmark, "~> 1.0", [hex: :earmark, optional: false]}]}}
2+
"ex_doc": {:hex, :ex_doc, "0.14.3", "e61cec6cf9731d7d23d254266ab06ac1decbb7651c3d1568402ec535d387b6f7", [:mix], [{:earmark, "~> 1.0", [hex: :earmark, optional: false]}]},
3+
"gproc": {:hex, :gproc, "0.6.1", "4579663e5677970758a05d8f65d13c3e9814ec707ad51d8dcef7294eda1a730c", [:rebar3], []}}

0 commit comments

Comments
 (0)