[erlang-questions] list comprehensions speed
Thomas Lindgren
thomasl_erlang@REDACTED
Tue Feb 25 16:22:45 CET 2014
As a related point, I wouldn't mind if, say, Hipe or that forthcoming BEAM/JIT compiler generated code similar to C for these sorts of functions. (It would at least be quite interesting if someone investigated codegen for tight-ish loops further. MSc thesis, anyone?)
Basically, less code in C please ...
Best,
Thomas
On Tuesday, February 25, 2014 3:28 PM, Ivan Uemlianin <ivan@REDACTED> wrote:
There's also lists:keyfind/3 you could try
>
> http://www.erlang.org/doc/man/lists.html#keyfind-3
>
>I think the lists are written in C, so they should be fast.
>
>Ivan
>
>
>On 25/02/2014 13:08, Oleg wrote:
>> Hello.
>>
>> I'm erlang newbie. Don't beat me, please :-), if this question is obvious.
>>
>> I have a list of key-value pairs:
>>
>> A=[{"name1", 1}, {"name2", 77}, {"name3", 33}, {"name4", 234}].
>>
>> What is faster:
>>
>> [ Value || {Name, Value} <- A, string:equal(Name, "name3")].
>>
>> Or:
>>
>> get_value(Key, []) ->
>> [].
>> get_value(Key, [H|T]) ->
>> {Name, Value} = H,
>> case string:equal(Name, Key) of
>> true ->
>> [Value];
>> false ->
>> get_value(Key, T)
>> end.
>>
>> start() ->
>> get_value("name3", A).
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions
>>
>
>--
>============================================================
>Ivan A. Uemlianin PhD
>Llaisdy
>Speech Technology Research and Development
>
> ivan@REDACTED
> www.llaisdy.com
> llaisdy.wordpress.com
> github.com/llaisdy
> www.linkedin.com/in/ivanuemlianin
>
> festina lente
>
>============================================================
>_______________________________________________
>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/20140225/d56d8481/attachment.htm>
More information about the erlang-questions
mailing list