СИ
Size: a a a
СИ
СИ
V
AV
AA
PG
DK
DK
SL
ML
SL
PK
1> L = lists:seq(1, 10000).
2> M = #{key1 => value1, key2 => value2}.
3> R = {foo, value, 1,2,3,4,5,6}.
4> timer:tc(fun() -> lists:foreach(fun(_) -> {foo, _, _, _, _, _, _, _} = R end, L) end).
{6866,ok}
5> timer:tc(fun() -> lists:foreach(fun(_) -> {foo, _, _, _, _, _, _, _} = R end, L) end).
{7383,ok}
6> timer:tc(fun() -> lists:foreach(fun(_) -> element(2, R) end, L) end).
{8597,ok}
7> timer:tc(fun() -> lists:foreach(fun(_) -> element(2, R) end, L) end).
{6669,ok}
8> timer:tc(fun() -> lists:foreach(fun(_) -> #{key1 := _} = M end, L) end).
{69632,ok}
9> timer:tc(fun() -> lists:foreach(fun(_) -> #{key1 := _} = M end, L) end).
{70139,ok}
10> timer:tc(fun() -> lists:foreach(fun(_) -> maps:get(key1, M, undefined) end, L) end).
{13613,ok}
11> timer:tc(fun() -> lists:foreach(fun(_) -> maps:get(key1, M, undefined) end, L) end).
{16758,ok}
12> timer:tc(fun() -> lists:foreach(fun(_) -> ok end, L) end).
{2108,ok}
13> timer:tc(fun() -> lists:foreach(fun(_) -> ok end, L) end).
{2963,ok}
LL
1> L = lists:seq(1, 10000).
2> M = #{key1 => value1, key2 => value2}.
3> R = {foo, value, 1,2,3,4,5,6}.
4> timer:tc(fun() -> lists:foreach(fun(_) -> {foo, _, _, _, _, _, _, _} = R end, L) end).
{6866,ok}
5> timer:tc(fun() -> lists:foreach(fun(_) -> {foo, _, _, _, _, _, _, _} = R end, L) end).
{7383,ok}
6> timer:tc(fun() -> lists:foreach(fun(_) -> element(2, R) end, L) end).
{8597,ok}
7> timer:tc(fun() -> lists:foreach(fun(_) -> element(2, R) end, L) end).
{6669,ok}
8> timer:tc(fun() -> lists:foreach(fun(_) -> #{key1 := _} = M end, L) end).
{69632,ok}
9> timer:tc(fun() -> lists:foreach(fun(_) -> #{key1 := _} = M end, L) end).
{70139,ok}
10> timer:tc(fun() -> lists:foreach(fun(_) -> maps:get(key1, M, undefined) end, L) end).
{13613,ok}
11> timer:tc(fun() -> lists:foreach(fun(_) -> maps:get(key1, M, undefined) end, L) end).
{16758,ok}
12> timer:tc(fun() -> lists:foreach(fun(_) -> ok end, L) end).
{2108,ok}
13> timer:tc(fun() -> lists:foreach(fun(_) -> ok end, L) end).
{2963,ok}
LL
1> L = lists:seq(1, 10000).
2> M = #{key1 => value1, key2 => value2}.
3> R = {foo, value, 1,2,3,4,5,6}.
4> timer:tc(fun() -> lists:foreach(fun(_) -> {foo, _, _, _, _, _, _, _} = R end, L) end).
{6866,ok}
5> timer:tc(fun() -> lists:foreach(fun(_) -> {foo, _, _, _, _, _, _, _} = R end, L) end).
{7383,ok}
6> timer:tc(fun() -> lists:foreach(fun(_) -> element(2, R) end, L) end).
{8597,ok}
7> timer:tc(fun() -> lists:foreach(fun(_) -> element(2, R) end, L) end).
{6669,ok}
8> timer:tc(fun() -> lists:foreach(fun(_) -> #{key1 := _} = M end, L) end).
{69632,ok}
9> timer:tc(fun() -> lists:foreach(fun(_) -> #{key1 := _} = M end, L) end).
{70139,ok}
10> timer:tc(fun() -> lists:foreach(fun(_) -> maps:get(key1, M, undefined) end, L) end).
{13613,ok}
11> timer:tc(fun() -> lists:foreach(fun(_) -> maps:get(key1, M, undefined) end, L) end).
{16758,ok}
12> timer:tc(fun() -> lists:foreach(fun(_) -> ok end, L) end).
{2108,ok}
13> timer:tc(fun() -> lists:foreach(fun(_) -> ok end, L) end).
{2963,ok}
elixir
помимо рекордов есть ещё и struct
, которые выглядят %Structure{key: value}
. Вот они реализованы на мапахPK
PK
LL
key lists
, это дольше чем одна ассемблерная операцияСИ
В
PK