[erlang-questions] Todays Topic: Performance Stuffs->records vs maps vs proplists
Gilberio Carmenates Garcia
co7eb@REDACTED
Thu Aug 20 18:42:16 CEST 2015
Hi all, well I think maps are super nice, I will do the test again but including lists:keyfind/3... to compare all values.
How I can do to test memory occupation but with fine details? because, I see it in observer and all cases have no appreciable difference between them.
Regards test data size, I didn't state it because I use the same data in all cases, but in its correspondent format, i.e. for proplists I use [{id, N}, ...] and for maps: #{id => N, ...} and so on. I only included a few data, I think was 9 keys with its number values, but for the number values I used the same variable N as I was decreasing it in the recursive loop. #{ id => N, name => N, ...}.
I will be doing some other interesting test since time to time. I have another one I will post later soon.
Best regards,
Ivan (son of Gilberio).
-----Mensaje original-----
De: Garrett Smith [mailto:g@REDACTED]
Enviado el: lunes, 17 de agosto de 2015 6:27
Para: Erik Søe Sørensen
CC: Gilberio Carmenates Garcia; Erlang Questions
Asunto: Re: [erlang-questions] Todays Topic: Performance Stuffs->records vs maps vs proplists
I have this from erlang-bench:
https://github.com/gar1t/erlang-bench/blob/master/name-lookup.escript
lists:keyfind is indeed faster, but surprisingly proplists is plenty fast too.
The use case I was interested in there is small list (less than 100
items) lookup, which is common for configuration data.
Fast is relative of course. And short of a real application
bottleneck, completely pointless to obsess over. But it can be
interesting and fun to argue about, like politics.
Ivan, it'd be great to update that benchmark with maps :)
On Mon, Aug 17, 2015 at 2:30 AM, Erik Søe Sørensen <eriksoe@REDACTED> wrote:
> Hi -
> As for proplists, try replacing it with the simpler and faster
> lists:keyfind/3.
> Also, you don't state the size of the data structure you're manipulating -
> only the number of iterations.
>
> Den 16/08/2015 20.08 skrev "Gilberio Carmenates Garcia"
> <co7eb@REDACTED>:
>>
>> 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).
>>
>>
>>
>>
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions
>>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
More information about the erlang-questions
mailing list