<html><head></head><body>As a first step try a compiled version, not a test in a shell. <br><br><div class="gmail_quote">On 18 May 2016 1:35:49 PM AEST, Avinash Dhumane <nistrigunya@gmail.com> wrote:<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div dir="ltr"><div>For my algorithm trading application, gains even in 5 to 10 microseconds matter. <br /><br />I used maps extensively to improve expressiveness of the design. <br /><br />But, here is a small observation about maps. I am not sure if the performance variation seen is indeed true, or if my test case is wrong. In either case, please point me to the right way of efficiently using of maps. <br /><br />avinash@veda:~/tws$ erl<br />Erlang/OTP 18 [erts-7.3] [source] [64-bit] [smp:2:2] [async-threads:10] [hipe] [kernel-poll:false]<br /><br />Eshell V7.3 (abort with ^G)<br /><br /></div><div>%%% compute average of timer:tc() return values (timings)<br /><br /></div><div>1> Avg = fun(PerfList) -> Sum = lists:sum(lists:map(fun({Time, _}) -> Time end, PerfList)), Len = erlang:length(PerfList), Sum div Len end.<br />#Fun<erl_eval.6.50752066><br /><br /></div><div>%%% a test map of size 3<br /><br /></div><div>2> Map = #{{a, 1} => 100, {a, 2} => 200,
{a, 3} => 300}.<br />#{{a,1} => 100,{a,2} => 200,{a,3} => 300}<br /><br /></div><div>%%% performance: without maps:get()<br /><br /></div><div>3> PerfList1 = lists:map(fun(_) -> timer:tc(fun() -> K1 = {a, 1}, K2 = {a, 2}, K3 = {a, 3}, #{K1 := V1, K2 := V2, K3 := V3} = Map, {V1, V2, V3} end) end, lists:seq(1,100)).<br />[{111,{100,200,300}},<br /> {81,{100,200,300}},<br /> {88,{100,200,300}},<br /></div>.....details deleted.....<br /><div> {91,{100,200,...}},<br /> {83,{100,...}},<br /> {85,{...}},<br /> {107,...},<br /> {...}|...]<br /><br /></div><div>%%% performance: with maps:get()<br /><br /></div><div>4> PerfList2 = lists:map(fun(_) -> timer:tc(fun() -> {maps:get({a,1}, Map), maps:get({a,2}, Map), maps:get({a,3}, Map)} end) end, lists:seq(1, 100)).<br />[{13,{100,200,300}},<br /> {12,{100,200,300}},<br /> {33,{100,200,300}},<br />.....details deleted.....<br /> {13,{100,200,...}},<br /> {12,{100,...}},<br /> {12,{...}},<br
/> {12,...},<br /> {...}|...]<br /><br /></div><div>%%% compare performance: maps:get() is 7-times faster<br /><br /></div><div>5> {Avg(PerfList1), Avg(PerfList2)}.<br />{89,13}<br />6><br /></div></div>
<p style="margin-top: 2.5em; margin-bottom: 1em; border-bottom: 1px solid #000"></p><pre class="k9mail"><hr /><br />erlang-questions mailing list<br />erlang-questions@erlang.org<br /><a href="http://erlang.org/mailman/listinfo/erlang-questions">http://erlang.org/mailman/listinfo/erlang-questions</a><br /></pre></blockquote></div><br>
-- <br>
Best wishes, <br>
Dmitry Belyaev</body></html>