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

Mikhail Sobolev <>
Thu May 5 10:37:27 CEST 2011


We have a lot of proplists, where the keys (atoms) need to be
converted to strings.

The first idea was to create another proplist with the necessary
mapping and write a function that would do the things.  After
considering it for a while (without actually writing any code :)),
Erlang pattern matching came to mind.  After looking around a bit I
saw statements like "for rather short proplists (10s of elements), the
speed will be pretty much the same".

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)
2) why there's such a big difference in time? (proplists module
provides BIFs, right?)
3) are there any other ways to do what we want?

The current inclination is to generate a function based on the mapping
and then utilize the produced function to do the job.

Any answers/comments/suggestions? :)


[1]  https://gist.github.com/956717

More information about the erlang-questions mailing list