Skip to content

Commit 7bbdbdb

Browse files
committed
Update bench for local/remote
1 parent fcbf05a commit 7bbdbdb

File tree

3 files changed

+73
-37
lines changed

3 files changed

+73
-37
lines changed

bench/local_vs_module.exs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,34 @@
1-
defmodule Foo do
2-
def foo(x), do: 1 + x
3-
end
4-
51
defmodule Bench do
62
# uncomment to get S file
73
# @compile :S
84

95
def module(enum) do
10-
Enum.each(enum, &Foo.foo/1)
6+
Enum.each(enum, &__MODULE__.foo/1)
117
end
128

139
def local(enum) do
1410
Enum.each(enum, &foo/1)
1511
end
1612

13+
def local_closure, do: &foo/1
14+
def remote_closure, do: &__MODULE__.foo/1
15+
1716
def foo(x), do: 1 + x
1817
end
1918

2019
inputs = [
2120
{"list", Enum.to_list(1..1000)}
2221
]
2322

23+
local_closure = Bench.local_closure()
24+
remote_closure = Bench.remote_closure()
25+
2426
Benchee.run(
2527
[
2628
module: &Bench.module/1,
27-
local: &Bench.local/1
29+
local: &Bench.local/1,
30+
local_closure: &Enum.each(&1, local_closure),
31+
remote_closure: &Enum.each(&1, remote_closure)
2832
],
2933
inputs: inputs
3034
)

bench/local_vs_module.exs.S

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
{exports, [{'__info__',1},
44
{foo,1},
55
{local,1},
6+
{local_closure,0},
67
{module,1},
78
{module_info,0},
8-
{module_info,1}]}.
9+
{module_info,1},
10+
{remote_closure,0}]}.
911

1012
{attributes, []}.
1113

12-
{labels, 22}.
14+
{labels, 26}.
1315

1416

1517
{function, '__info__', 1, 2}.
@@ -44,11 +46,15 @@
4446
{move,{atom,'Elixir.Bench'},{x,0}}.
4547
return.
4648
{label,5}.
47-
{move,{literal,[{foo,1},{local,1},{module,1}]},{x,0}}.
49+
{move,{literal,[{foo,1},
50+
{local,1},
51+
{local_closure,0},
52+
{module,1},
53+
{remote_closure,0}]},
54+
{x,0}}.
4855
return.
4956
{label,6}.
50-
{move,{literal,<<249,220,148,233,109,149,24,191,155,116,221,51,167,22,151,
51-
183>>},
57+
{move,{literal,<<23,253,119,194,33,204,205,227,211,208,5,195,55,16,104,222>>},
5258
{x,0}}.
5359
return.
5460
{label,7}.
@@ -59,12 +65,12 @@
5965
{move,{atom,'Elixir.Bench'},{x,0}}.
6066
{call_ext_only,2,{extfunc,erlang,get_module_info,2}}.
6167
{label,9}.
62-
{call_only,1,{f,21}}. % '-inlined-__info__/1-'/1
68+
{call_only,1,{f,25}}. % '-inlined-__info__/1-'/1
6369

6470

6571
{function, foo, 1, 11}.
6672
{label,10}.
67-
{line,[{location,"bench/local_vs_module.exs",15}]}.
73+
{line,[{location,"bench/local_vs_module.exs",16}]}.
6874
{func_info,{atom,'Elixir.Bench'},{atom,foo},1}.
6975
{label,11}.
7076
{gc_bif,'+',{f,0},1,[{x,0},{integer,1}],{x,0}}.
@@ -73,48 +79,68 @@
7379

7480
{function, local, 1, 13}.
7581
{label,12}.
76-
{line,[{location,"bench/local_vs_module.exs",11}]}.
82+
{line,[{location,"bench/local_vs_module.exs",9}]}.
7783
{func_info,{atom,'Elixir.Bench'},{atom,local},1}.
7884
{label,13}.
7985
{test_heap,{alloc,[{words,0},{floats,0},{funs,1}]},1}.
8086
{make_fun3,{f,11},0,0,{x,1},{list,[]}}.
8187
{'%',{var_info,{x,1},[{fun_type,{t_number,any}}]}}.
82-
{line,[{location,"bench/local_vs_module.exs",12}]}.
88+
{line,[{location,"bench/local_vs_module.exs",10}]}.
8389
{call_ext_only,2,{extfunc,'Elixir.Enum',each,2}}.
8490

8591

86-
{function, module, 1, 15}.
92+
{function, local_closure, 0, 15}.
8793
{label,14}.
88-
{line,[{location,"bench/local_vs_module.exs",7}]}.
89-
{func_info,{atom,'Elixir.Bench'},{atom,module},1}.
94+
{line,[{location,"bench/local_vs_module.exs",13}]}.
95+
{func_info,{atom,'Elixir.Bench'},{atom,local_closure},0}.
9096
{label,15}.
91-
{move,{literal,fun 'Elixir.Foo':foo/1},{x,1}}.
92-
{line,[{location,"bench/local_vs_module.exs",8}]}.
93-
{call_ext_only,2,{extfunc,'Elixir.Enum',each,2}}.
97+
{test_heap,{alloc,[{words,0},{floats,0},{funs,1}]},0}.
98+
{make_fun3,{f,11},0,0,{x,0},{list,[]}}.
99+
{'%',{var_info,{x,0},[{fun_type,{t_number,any}}]}}.
100+
return.
94101

95102

96-
{function, module_info, 0, 17}.
103+
{function, module, 1, 17}.
97104
{label,16}.
105+
{line,[{location,"bench/local_vs_module.exs",5}]}.
106+
{func_info,{atom,'Elixir.Bench'},{atom,module},1}.
107+
{label,17}.
108+
{move,{literal,fun 'Elixir.Bench':foo/1},{x,1}}.
109+
{line,[{location,"bench/local_vs_module.exs",6}]}.
110+
{call_ext_only,2,{extfunc,'Elixir.Enum',each,2}}.
111+
112+
113+
{function, remote_closure, 0, 19}.
114+
{label,18}.
115+
{line,[{location,"bench/local_vs_module.exs",14}]}.
116+
{func_info,{atom,'Elixir.Bench'},{atom,remote_closure},0}.
117+
{label,19}.
118+
{move,{literal,fun 'Elixir.Bench':foo/1},{x,0}}.
119+
return.
120+
121+
122+
{function, module_info, 0, 21}.
123+
{label,20}.
98124
{line,[]}.
99125
{func_info,{atom,'Elixir.Bench'},{atom,module_info},0}.
100-
{label,17}.
126+
{label,21}.
101127
{move,{atom,'Elixir.Bench'},{x,0}}.
102128
{call_ext_only,1,{extfunc,erlang,get_module_info,1}}.
103129

104130

105-
{function, module_info, 1, 19}.
106-
{label,18}.
131+
{function, module_info, 1, 23}.
132+
{label,22}.
107133
{line,[]}.
108134
{func_info,{atom,'Elixir.Bench'},{atom,module_info},1}.
109-
{label,19}.
135+
{label,23}.
110136
{move,{x,0},{x,1}}.
111137
{move,{atom,'Elixir.Bench'},{x,0}}.
112138
{call_ext_only,2,{extfunc,erlang,get_module_info,2}}.
113139

114140

115-
{function, '-inlined-__info__/1-', 1, 21}.
116-
{label,20}.
141+
{function, '-inlined-__info__/1-', 1, 25}.
142+
{label,24}.
117143
{line,[]}.
118144
{func_info,{atom,'Elixir.Bench'},{atom,'-inlined-__info__/1-'},1}.
119-
{label,21}.
120-
{jump,{f,20}}.
145+
{label,25}.
146+
{jump,{f,24}}.

bench/local_vs_module.results.txt

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Operating System: macOS
22
CPU Information: Apple M1
33
Number of Available Cores: 8
44
Available memory: 16 GB
5-
Elixir 1.16.2
5+
Elixir 1.17.0
66
Erlang 27.0
77

88
Benchmark suite executing with the following configuration:
@@ -12,16 +12,22 @@ memory time: 0 ns
1212
reduction time: 0 ns
1313
parallel: 1
1414
inputs: list
15-
Estimated total run time: 14 s
15+
Estimated total run time: 28 s
1616

1717
Benchmarking module with input list ...
1818
Benchmarking local with input list ...
19+
Benchmarking local_closure with input list ...
20+
Benchmarking remote_closure with input list ...
1921

2022
##### With input list #####
21-
Name ips average deviation median 99th %
22-
module 306.43 K 3.26 μs ±182.87% 3.21 μs 4.17 μs
23-
local 301.59 K 3.32 μs ±199.86% 3.21 μs 3.92 μs
23+
Name ips average deviation median 99th %
24+
remote_closure 297.66 K 3.36 μs ±143.38% 3.29 μs 4.25 μs
25+
local_closure 293.46 K 3.41 μs ±124.56% 3.33 μs 4.46 μs
26+
module 290.89 K 3.44 μs ±20.06% 3.42 μs 4.38 μs
27+
local 275.23 K 3.63 μs ±273.55% 3.50 μs 4.54 μs
2428

2529
Comparison:
26-
module 306.43 K
27-
local 301.59 K - 1.02x slower +0.0525 μs
30+
remote_closure 297.66 K
31+
local_closure 293.46 K - 1.01x slower +0.0481 μs
32+
module 290.89 K - 1.02x slower +0.0782 μs
33+
local 275.23 K - 1.08x slower +0.27 μs

0 commit comments

Comments
 (0)