[erlang-questions] list comprehensions speed

Björn-Egil Dahlberg <>
Tue Feb 25 17:29:28 CET 2014


On 2014-02-25 16:22, Thomas Lindgren wrote:
> 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 ...
I think that is the whole point with a tracing jit =)
"Tight-ish" loops gets traced and compiled to native code.

Erlangs compiler can only do so much since remote module calls can't be 
inlined .. the loader could do it but that would in essence move a lot 
of the compiler to the loader. A jit will solve this with tracing.

For all you C lovers .. C can absolutely be fast but "erlang functions 
implemented in C" has to do pretty much the same work with 
boxing/unboxing as the VM has to. The gain is less(no) instruction 
dispatching and it may do clever memory allocation which will speed 
things up .. but it also can destroy Erlangs soft-real-time properties.

Implement your code in Erlang.

// Björn-Egil

>
> Best,
> Thomas
>
>
> On Tuesday, February 25, 2014 3:28 PM, Ivan Uemlianin 
> <> 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
>     >  <mailto:>
>     > http://erlang.org/mailman/listinfo/erlang-questions
>     >
>
>     -- 
>     ============================================================
>     Ivan A. Uemlianin PhD
>     Llaisdy
>     Speech Technology Research and Development
>
>      <mailto:>
>                           www.llaisdy.com
>                               llaisdy.wordpress.com
>                   github.com/llaisdy
>     www.linkedin.com/in/ivanuemlianin
>
>                             festina lente
>
>     ============================================================
>     _______________________________________________
>     erlang-questions mailing list
>      <mailto:>
>     http://erlang.org/mailman/listinfo/erlang-questions
>
>
>
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140225/6fd71974/attachment.html>


More information about the erlang-questions mailing list