<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Feb 25, 2014 at 2:08 PM, Oleg <span dir="ltr"><<a href="mailto:lego12239@yandex.ru" target="_blank">lego12239@yandex.ru</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Hello.<br></blockquote><div><br></div><div>Hi Oleg!</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
I'm erlang newbie. Don't beat me, please :-), if this question is obvious.<br>
<br>
I have a list of key-value pairs:<br>
<br>
A=[{"name1", 1}, {"name2", 77}, {"name3", 33}, {"name4", 234}].<br>
<br>
What is faster:<br>
<br></blockquote><div><br></div><div>The way you can figure this out is by following three basic rules:</div><div><br></div><div>1. use timer:tc/1 to measure the execution time.</div><div>2. Remember to do it in a module which is compiled. The shell interprets.</div>
<div>3. Remember to only measure what you want to measure!</div><div><br></div><div><a href="https://gist.github.com/jlouis/9209794">https://gist.github.com/jlouis/9209794</a><br></div><div><br></div><div>has an example. Note that for a 4-element list, the executiion speed doesn't really matter that much. For a 1000 element list, the speed of `lists:keyfind/3` begins to show itself. The reason is that keyfind is a BIF and is implemented in C.</div>
<div><br></div><div>Also, like motiejus wrote, you should probably run more than a single run in order to figure out what the best number of rounds are. And remember to call the garbage_collector in between to clean up a bit.</div>
<div><br></div><div> </div></div>-- <br>J.
</div></div>