-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbench.exs
79 lines (71 loc) · 1.85 KB
/
bench.exs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# SPDX-FileCopyrightText: 2022 Frank Hunleth
#
# SPDX-License-Identifier: Apache-2.0
#
defmodule NonMatchingSub do
use GenServer
def init(_) do
PropertyTable.subscribe(BencheeTable, ["non_matching", :_])
{:ok, :no_state}
end
end
create_properties = fn values -> for v <- values, do: {["first", "#{v}"], v} end
create_sub = fn ->
{:ok, pid} = GenServer.start(NonMatchingSub, [])
pid
end
starter_properties = create_properties.(1_000_000..1_000_100)
inputs = [
{"100 properties/0 subs",
%{
initial_properties: starter_properties,
non_matching_subscribers: 0,
add: create_properties.(1..100)
}},
{"1000 properties/0 subs",
%{
initial_properties: starter_properties,
non_matching_subscribers: 0,
add: create_properties.(1..1000)
}},
{"100 properties/2 subs",
%{
initial_properties: starter_properties,
non_matching_subscribers: 2,
add: create_properties.(1..100)
}},
{"1000 properties/2 subs",
%{
initial_properties: starter_properties,
non_matching_subscribers: 2,
add: create_properties.(1..1000)
}}
]
Benchee.run(
%{
"insertion" => fn input ->
Enum.each(input.add, fn {k, v} -> PropertyTable.put(BencheeTable, k, v) end)
input
end,
"get 1000x" => fn input ->
for _ <- 1..1000, do: PropertyTable.get(BencheeTable, ["first", "1000042"])
input
end
},
warmup: 1,
time: 5,
memory_time: 1,
inputs: inputs,
before_each: fn input ->
{:ok, pid} = PropertyTable.start_link(name: BencheeTable)
Enum.each(input.initial_properties, fn {k, v} -> PropertyTable.put(BencheeTable, k, v) end)
for _ <- 1..input.non_matching_subscribers do
create_sub.()
end
Map.put(input, :supervisor, pid)
end,
after_each: fn input ->
Supervisor.stop(input.supervisor)
end,
formatters: [Benchee.Formatters.Console]
)