From d9694a992a38279a878f0cee83734f8506cdfff9 Mon Sep 17 00:00:00 2001 From: Scott Lystig Fritchie Date: Thu, 25 Jun 2015 16:08:04 +0900 Subject: [PATCH] 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 --- src/machi_pb_wrap.erl | 11 +++-------- test/machi_flu1_test.erl | 2 +- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/machi_pb_wrap.erl b/src/machi_pb_wrap.erl index ec84de3..8456602 100644 --- a/src/machi_pb_wrap.erl +++ b/src/machi_pb_wrap.erl @@ -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; diff --git a/test/machi_flu1_test.erl b/test/machi_flu1_test.erl index c9c24bb..3c41e3d 100644 --- a/test/machi_flu1_test.erl +++ b/test/machi_flu1_test.erl @@ -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(),