lists:keyfind() 快于 proplists:get_value()
proplists_listkeyfind() ->
TestCase = [{A, A} || A <- lists:seq(1, 10000)],
io:format("single thread==>(prop lists:get_value) ~p~n",
[begin {Time1, _} = timer:tc(fun() ->
proplists:get_value(10000, TestCase) end), Time1 end]),
io:format("single thread==>(lists:keyfind) ~p~n",
[begin {Time2, _} = timer:tc(fun() ->
lists:keyfind(10000, 1, TestCase) end), Time2 end]).
测试结果:
2> erlang_po:proplists_listkeyfind().
single thread==>(proplists:get_value) : 460
single thread==>(lists:key find) : 27