[erlang-questions] 回复: which one is more efficiency? ets or pattern match?
饕餮
249505968@REDACTED
Wed Mar 16 12:37:01 CET 2016
thank you for the advise~
The whole thing is that:
My team use the ets way before (load a csv file to ets).
And now we are thinking about to use erlang beam file to replace it(pattern match),because it's easy to hot code load.
But someone is afraid about the efficiency of pattern match.(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).
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).
If both way is very efficiency, we will choose the pattern match solution(translate the csv file to erlang file).
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)?
thank you again~
------------------ 原始邮件 ------------------
发件人: "Joe Armstrong";<erlang@REDACTED>;
发送时间: 2016年3月16日(星期三) 下午5:38
收件人: "饕餮"<249505968@REDACTED>;
抄送: "erlang-questions"<erlang-questions@REDACTED>;
主题: Re: [erlang-questions] which one is more efficiency? ets or pattern match?
Your example suggests that the keys are strictly from 1..N
If this is the case then the array module *should be* the most efficient.
If the array module is not the most efficient and it turned out that
(say ets) is more
efficient then parts of the array module should be rewritten using ets
to reflect this.
My point here is not only should you ask what is the most efficient
way to do X, but
that the solution should be in the place where you expect to find it.
If the array indices are in gappy integer sequences then you should use
sparce_arrays.erl - but this hasn't been written, so go write it :-)
If the array indices are unpredictable use maps or ets - you'd have to
measure to find the best
way.
Cheers
/Joe
On Wed, Mar 16, 2016 at 9:05 AM, 饕餮 <249505968@REDACTED> wrote:
> erlang pattern match file could be written like :
>
> -module(config).
> get(1) -> 11,
> get(2) -> 22,
> .....
> get(1000001) -> 12312,
> get(_) -> none.
>
> When I need get some data,
> ets:lookup(some_table, some_value)
> &
> config:get(some_value)
>
> Which one is more efficiency?
> How much different between them?
>
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20160316/fb383b47/attachment.htm>
More information about the erlang-questions
mailing list