Skip to content

Instantly share code, notes, and snippets.

@sinasamavati
Last active January 1, 2016 19:09
Show Gist options
  • Save sinasamavati/8188159 to your computer and use it in GitHub Desktop.
Save sinasamavati/8188159 to your computer and use it in GitHub Desktop.
-module(lists_vs_proplists).
-export([lists/0]).
-export([proplists/0]).
-define(SIZE, 10).
-define(KEY, ?SIZE - 1).
-define(TIMES, 1000).
lists() ->
L = make_list(?SIZE, []),
F = fun() ->
case lists:keyfind(?KEY, 1, L) of
{_, V} ->
V;
_ ->
undefined
end
end,
%% {306,ok}
timer:tc(fun() -> test(L, F, ?TIMES) end).
proplists() ->
L = make_list(?SIZE, []),
F = fun() -> proplists:get_value(?KEY, L) end,
%% {1964,ok}
timer:tc(fun() -> test(L, F, ?TIMES) end).
make_list(0, Acc) ->
Acc;
make_list(N, Acc) ->
K = N - 1,
V = integer_to_list(N * 759),
make_list(K, [{K, V}|Acc]).
test(_, _, 0) ->
ok;
test(L, F, N) ->
F(),
test(L, F, N-1).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment