[erlang-questions] Todays Topic: Performance Stuffs->records vs maps vs proplists
Gilberio Carmenates Garcia
co7eb@REDACTED
Sun Aug 16 19:47:47 CEST 2015
Hi everyone here are some interesting tests about performance in Erlang.
Today's Topic: performance stuffs->records vs maps vs proplists
Test made against the same data represented in three format records, maps
and proplists.
Test case value: 10 000 000 iterations.
Test case: get.
Records:
Rec#rec.id -> 237 ms
Maps:
maps:get(id, Map) -> 550 ms
{id := Id} = Map -> ~277 ms
Proplists:
proplists:get_value/lookup(id, PPL) -> ~1642 ms
Test case: create.
Records:
Rec = #rec{id = N, .} -> ~1046 ms
Maps:
Map = #{id = N, .} -> ~ 1440 ms
Proplists:
PPL = [{id, N}, .] -> ~2318 ms
Test case: update.
Records:
case 1 (~908 ms):
Rec2 = Rec#rec{id = N + N},
case 2 (~1057 ms):
Rec2 = Rec#rec{id = N, name = N, age = N, dog = N, cat = N, mow = N, tin
= N},
case 3: no equivalent
case 4: no equivalent
Maps:
case 1 (~3013 ms):
Map2 = Map#{id => N + N},
case 2 (~ 4441 ms):
Map2 = Map#{id => N, name => N, age => N, dog => N, cat => N, mow => N,
tin => N},
case 3 (~952 ms):
Map2 = maps:update(id, N + 1, Map)
case 4 (~6054 ms)
Map2 = maps:update(id, N + 1, Map),
Map3 = maps:update(name, N + 1, Map2),
Map4 = maps:update(age, N + 1, Map3),
Map5 = maps:update(dog, N + 1, Map4),
Map6 = maps:update(cat, N + 1, Map5),
Map7 = maps:update(mow, N + 1, Map6),
Map8 = maps:update(tin, N + 1, Map7),
Proplists:
case 1: no equivalent
case 2: no equivalent
case 3: (~1529 ms)
PPL2 = lists:keystore(id, 1, PPL, {id, N + N}),
case 4: (~30705 ms)
PPL2 = lists:keystore(id, 1, PPL, {id, N + N}),
PPL3 = lists:keystore(name, 1, PPL2, {name, N + N}),
PPL4 = lists:keystore(age, 1, PPL3, {age, N + N}),
PPL5 = lists:keystore(dog, 1, PPL4, {dog, N + N}),
PPL6 = lists:keystore(cat, 1, PPL5, {cat, N + N}),
PPL7 = lists:keystore(mow, 1, PPL6, {mow, N + N}),
PPL8 = lists:keystore(tin, 1, PPL7, {tin, N + N}),
What about that? I think using maps:get/2 is not so fast as using map
pattern matching.
Cheers,
Ivan (son of Gilberio).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150816/a56ed86a/attachment.htm>
More information about the erlang-questions
mailing list