<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:10pt"><div>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?) </div><div><br></div><div style="color: rgb(0, 0, 0); font-size: 13px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal;">Basically, less code in C please ...</div><div><br></div><div style="color: rgb(0, 0, 0); font-size: 13px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal;">Best,</div><div style="color: rgb(0, 0, 0); font-size: 13px;
font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal;">Thomas</div><div class="yahoo_quoted" style="display: block;"> <br> <br> <div style="font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 10pt;"> <div style="font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 12pt;"> <div dir="ltr"> <font size="2" face="Arial"> On Tuesday, February 25, 2014 3:28 PM, Ivan Uemlianin <ivan@llaisdy.com> wrote:<br> </font> </div> <blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; margin-top: 5px; padding-left: 5px;"> <div class="y_msg_container">There's also lists:keyfind/3 you could try<br clear="none"><br clear="none"> <a shape="rect" href="http://www.erlang.org/doc/man/lists.html#keyfind-3"
target="_blank">http://www.erlang.org/doc/man/lists.html#keyfind-3</a><br clear="none"><br clear="none">I think the lists are written in C, so they should be fast.<br clear="none"><br clear="none">Ivan<br clear="none"><br clear="none"><br clear="none">On 25/02/2014 13:08, Oleg wrote:<br clear="none">> Hello.<br clear="none">><br clear="none">> I'm erlang newbie. Don't beat me, please :-), if this question is obvious.<br clear="none">><br clear="none">> I have a list of key-value pairs:<br clear="none">><br clear="none">> A=[{"name1", 1}, {"name2", 77}, {"name3", 33}, {"name4", 234}].<br clear="none">><br clear="none">> What is faster:<br clear="none">><br clear="none">> [ Value || {Name, Value} <- A, string:equal(Name, "name3")].<br clear="none">><br clear="none">> Or:<br clear="none">><br clear="none">> get_value(Key, []) -><br clear="none">> [].<br clear="none">>
get_value(Key, [H|T]) -><br clear="none">> {Name, Value} = H,<br clear="none">> case string:equal(Name, Key) of<br clear="none">> true -><br clear="none">> [Value];<br clear="none">> false -><br clear="none">> get_value(Key, T)<br clear="none">> end.<br clear="none">><br clear="none">> start() -><br clear="none">> get_value("name3", A).<br clear="none">> _______________________________________________<br clear="none">> erlang-questions mailing list<br clear="none">> <a shape="rect" ymailto="mailto:erlang-questions@erlang.org" href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br clear="none">> <a shape="rect" href="http://erlang.org/mailman/listinfo/erlang-questions"
target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br clear="none">><br clear="none"><br clear="none">-- <br clear="none">============================================================<br clear="none">Ivan A. Uemlianin PhD<br clear="none">Llaisdy<br clear="none">Speech Technology Research and Development<br clear="none"><br clear="none"> <a shape="rect" ymailto="mailto:ivan@llaisdy.com" href="mailto:ivan@llaisdy.com">ivan@llaisdy.com</a><br clear="none"> www.llaisdy.com<br clear="none"> llaisdy.wordpress.com<br clear="none"> github.com/llaisdy<br clear="none">
www.linkedin.com/in/ivanuemlianin<br clear="none"><br clear="none"> festina lente<div class="yqt6375837379" id="yqtfd95983"><br clear="none">============================================================<br clear="none">_______________________________________________<br clear="none">erlang-questions mailing list<br clear="none"><a shape="rect" ymailto="mailto:erlang-questions@erlang.org" href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br clear="none"><a shape="rect" href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br clear="none"></div><br><br></div> </blockquote> </div> </div> </div> </div></body></html>