<div><span style="line-height: 1.5;">thank you for the advise~</span></div><div><span style="line-height: 1.5;">The whole thing is that:</span></div><div><span style="line-height: 1.5;">My team use the ets way before (load a csv file to ets).</span></div><div><span style="line-height: 1.5;">And now we are thinking about to use erlang beam file to replace it(pattern match),because it's easy to hot code load.</span></div><div><span style="line-height: 1.5;"><br></span></div><div><span style="line-height: 1.5;">But someone is afraid about the </span>efficiency<span style="line-height: 1.5;"> of pattern match.</span><span style="line-height: 1.5;">(because we are not very sure about the efficiency of pattern match,just heard that if the code is good, it will be a binary search)</span><span style="line-height: 1.5;">.</span></div><div><span style="line-height: 1.5;"><br></span></div><div>And the keys in pattern match will be all the same type (all of it in the same file will be either number or atom, sometime maybe string).</div><div><br></div><div>If both way is very efficiency, we will choose the pattern match solution(translate the csv file to erlang file).</div><div>So if the efficiency still pretty good for the pattern match, if they are not strictly from 1..N (and it will always be ascending,like 1, 3,5,6,7...N, or one, two, three<span style="line-height: 1.5;">)?</span></div><div><br></div><div><span style="line-height: 1.5;">thank you again~</span></div><div><div><br></div><div style="font-size: 12px;font-family: Arial Narrow;padding:2px 0 2px 0;">------------------ 原始邮件 ------------------</div><div style="font-size: 12px;background:#efefef;padding:8px;"><div><b>发件人:</b> "Joe Armstrong";<erlang@gmail.com>;</div><div><b>发送时间:</b> 2016年3月16日(星期三) 下午5:38</div><div><b>收件人:</b> "饕餮"<249505968@qq.com>; <wbr></div><div><b>抄送:</b> "erlang-questions"<erlang-questions@erlang.org>; <wbr></div><div><b>主题:</b> Re: [erlang-questions] which one is more efficiency? ets or pattern match?</div></div><div><br></div>Your example suggests that the keys are strictly from 1..N<br>If this is the case then the array module *should be* the most efficient.<br><br>If the array module is not the most efficient and it turned out that<br>(say ets) is more<br>efficient then parts of the array module should be rewritten using ets<br>to reflect this.<br><br>My point here is not only should you ask what is the most efficient<br>way to do X, but<br>that the solution should be in the place where you expect to find it.<br><br>If the array indices are in gappy integer sequences then you should use<br>sparce_arrays.erl - but this hasn't been written, so go write it :-)<br><br>If the array indices are unpredictable use maps or ets - you'd have to<br>measure to find the best<br>way.<br><br>Cheers<br><br>/Joe<br><br><br><br>On Wed, Mar 16, 2016 at 9:05 AM, 饕餮 <249505968@qq.com> wrote:<br>> erlang pattern match file could be written like :<br>><br>> -module(config).<br>> get(1) -> 11,<br>> get(2) -> 22,<br>> .....<br>> get(1000001) -> 12312,<br>> get(_) -> none.<br>><br>> When I need get some data,<br>> ets:lookup(some_table, some_value)<br>> &<br>> config:get(some_value)<br>><br>> Which one is more efficiency?<br>> How much different between them?<br>><br>><br>><br>> _______________________________________________<br>> erlang-questions mailing list<br>> erlang-questions@erlang.org<br>> http://erlang.org/mailman/listinfo/erlang-questions<br>><br></div>