Alright, use term_to_binary() for opaque/sexp-style encoding, only 15x slower.

machi_flu1_test: timing_pb_encoding_test_... speed factor=15.12 [2.678 s] ok
This commit is contained in:
Scott Lystig Fritchie 2015-06-25 16:08:04 +09:00
parent 2763b16ca2
commit d9694a992a
2 changed files with 4 additions and 9 deletions

View file

@ -67,7 +67,7 @@ conv_to_p_srvr(#mpb_p_srvr{name=Name,
proto_mod=to_atom(ProtoMod),
address=to_list(Address),
port=to_integer(Port),
props=dec_sexp(to_list(Props))}.
props=dec_sexp(Props)}.
enc_projection_v1(P) ->
%% Awww, flatten it here
@ -282,15 +282,10 @@ unmake_projection_resp(#mpb_ll_response{proj_la=#mpb_ll_listallprojectionsresp{
%%%%%%%%%%%%%%%%%%%
enc_sexp(T) ->
lists:flatten(io_lib:format("~w.", [T])).
term_to_binary(T).
dec_sexp(Bin) when is_binary(Bin) ->
dec_sexp(binary_to_list(Bin));
dec_sexp(String) when is_list(String) ->
{ok,Tks,_} = erl_scan:string(String),
{ok,E} = erl_parse:parse_exprs(Tks),
{value,Funs,_} = erl_eval:exprs(E,[]),
Funs.
binary_to_term(Bin).
enc_optional_sexp(undefined) ->
undefined;

View file

@ -230,7 +230,7 @@ timing_pb_encoding_test2() ->
ZZ = machi_pb:decode_mpb_ll_request(Bin),
_ = machi_pb_wrap:unmake_projection_req(ZZ)
end,
XX = lists:seq(1,30*1000),
XX = lists:seq(1,70*1000),
erlang:garbage_collect(),
RUN1 = timer:tc(fun() -> begin [_ = DoIt1() || _ <- XX], ok end end),
erlang:garbage_collect(),