<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Feb 25, 2014 at 4:12 PM, Garrett Smith <span dir="ltr"><<a href="mailto:g@rre.tt" target="_blank">g@rre.tt</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="">On Tue, Feb 25, 2014 at 2:08 PM, Oleg <<a href="mailto:lego12239@yandex.ru">lego12239@yandex.ru</a>> wrote:<br>
</div><div class="">>   Hello.<br>
><br>
> I'm erlang newbie. Don't beat me, please :-)<br>
<br>
</div>This is list is typically very docile -- but, for example, if you<br>
propose that Ericsson rename list comprehensions to "enumeration<br>
generators" to to appeal to Java programmers, well, brace yourself.<br>
<div class=""><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>
> [ Value || {Name, Value} <- A, string:equal(Name, "name3")].<br>
><br>
> Or:<br>
><br>
> get_value(Key, []) -><br>
>   [].<br>
> get_value(Key, [H|T]) -><br>
>   {Name, Value} = H,<br>
>   case string:equal(Name, Key) of<br>
>     true -><br>
>       [Value];<br>
>     false -><br>
>       get_value(Key, T)<br>
>   end.<br>
><br>
> start() -><br>
>   get_value("name3", A).<br>
<br>
</div>I have questions like this all the time. I use this thing to answer my<br>
own questions:<br>
<br>
<a href="https://github.com/gar1t/erlang-bench" target="_blank">https://github.com/gar1t/erlang-bench</a><br>
<br>
As I've stated emphatically before, these stats, like all stats, lie.<br>
*But* they are at least some attempt to measure and test.<br>
<br>
This particular test I think is similar to what you're looking for:<br>
<br>
<a href="https://github.com/gar1t/erlang-bench/blob/master/name-lookup.escript" target="_blank">https://github.com/gar1t/erlang-bench/blob/master/name-lookup.escript</a><br>
<br>
As Sean Cribbs pointed out, lists:keyfind/2 has super powers. I don't<br>
know at under what conditions it makes sense to move from its blazing<br>
fast O(N) scans to log(N) hash/tree lookups. Of course this can be<br>
tested.<br>
<br>
As Loïc Hoguin has pointed out, with zeal, performance characteristics<br>
tend to change under system load. I haven't seen what he's seen<br>
specifically, but he's very emphatic.<br>
<br>
And as Richard O'Keefe has pointed out, focus on getting your program<br>
to work correctly before worrying about performance.<br>
<br>
And as Joe Armstrong has pointed out, performance considerations comes<br>
after correctness *and* maintainability, except for known performance<br>
bottlenecks where it pays to make a compromise.<br></blockquote><div><br></div><div><br></div><div>  Yes - try the following:</div><div><br></div><div>   Repeat 10 times before meals, and before going to bed.</div><div><br>
</div><div>      " I must program as inefficiently and beautifully as possible"</div><div><br></div><div>  If the symptoms persist and you feel the need to program efficiently take a cold</div><div>  shower and a brisk bracing walk.</div>
<div><br></div><div>  Your job is to write beautiful and clear code.</div><div><br></div><div>   It is the compiler writers job to turn clear and beautiful code in quickly executing code.</div><div><br></div><div>   It is the language designers job to design languages that will make it difficult for</div>
<div>   you to shoot yourself in the foot.</div><div><br></div><div>  If you write clear code and you think it should run quickly and it does not do not</div><div>  optimise the code - tell the compiler writer to fix the compiler/run-time.</div>
<div><br></div><div>  We will get 1000+ core machines  within a few years - they are so bloody fast that we</div><div>  are having problems thinking of what we can use the CPU cycles for so please don't</div><div>  write efficient programs - otherwise we won't need the 1K core machines :-)</div>
<div><br></div><div>/Joe</div><div><br></div><div><br></div><div><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
I'd say, get in the habit of answering your own questions when it<br>
comes to "speed" -- I suggest playing around with erlang-bench, as<br>
it's super fun :)<br>
<br>
If you come up something interesting as an erlang-bench script, please<br>
pass it along as a pull request.<br>
<br>
Best of luck with your Erlang adventures!<br>
<span class="HOEnZb"><font color="#888888"><br>
Garrett<br>
</font></span><div class="HOEnZb"><div class="h5">_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</div></div></blockquote></div><br></div></div>