[erlang-questions] pattern matching vs proplists vs dict performance

Iñaki Garay igarai@REDACTED
Thu May 5 19:49:13 CEST 2011


On Thu, May 5, 2011 at 11:25, David Mercer <dmercer@REDACTED> wrote:
> On Thursday, May 05, 2011, Mikhail Sobolev wrote:
>
>> We have 10s of thousands of documents that require this kind of
>> conversion and this conversion has to be done fast.  So I decided to
>> write a little benchmark[1], which gave the definitive answer: pattern
>> matching is much faster (times on the test machine):
>>   * proplists -- ~4.9s
>>   * dicts -- ~3.0s
>>   * case inside the function -- ~0.86s
>>   * case as a separate function -- ~0.89s
>>
>> We have discussed the results and started to wonder:
>>
>> 1) are we doing something wrong? (we are all newbies in here)
>
> I don't think so.  I'd expect pattern matching in a case or function to be
> faster than iterating through a data structure, regardless of whether the
> data structure is a proplist or dict.
>
>> 2) why there's such a big difference in time? (proplists module
>> provides BIFs, right?)
>
> Again, I don't think so.  I consider proplists to be Erlang-only, and I'd be
> surprised if it were implemented in C.  Regardless, I'd still expect pattern
> matching to be faster.

You can find the code to the proplists module in
/usr/lib/erlang/lib/stdlib-1.17.1/src/proplists.erl
(or the equivalent directory in your system).

-- 
Iñaki Garay.



More information about the erlang-questions mailing list