[erlang-questions] mnesia:transform_table
Robert Virding
rvirding@REDACTED
Wed May 26 22:11:53 CEST 2010
On 26 May 2010 18:42, Igor Ribeiro Sucupira <igorrs@REDACTED> wrote:
> Since a dict consumes more space, the advantage of the proplist is the
> size. Basically, the dict will give you a performance gain that's
> irrelevant (unless you have many columns) and use more space.
In that case you might as well use an orddict which is generally
faster than an unsorted list, though not as fast as dict or gb_trees.
You will find that the relative size difference between
orddict/proplist and gb_trees decreases as the number of elements
grows.
> For example:
>
> 1> List = [{"firstname", "Igor"}, {"lastname", "Sucupira"}, {"gender",
> "male"}, {"birthdate", "02/15/1981"}].
> [{"firstname","Igor"},
> {"lastname","Sucupira"},
> {"gender","male"},
> {"birthdate","02/15/1981"}]
> 2> Dict= dict:from_list(List).
> {dict,4,16,16,8,80,48,
> {[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},
> {{[["lastname",83,117,99,117,112,105,114,97],
> ["gender",109,97,108,101]],
> [],
> [["birthdate",48,50,47,49,53,47,49,57,56,49]],
> [],[],[],[],[],[],[],[],[],
> [["firstname",73,103,111,114]],
> [],[],[]}}}
> 3> GB = gb_trees:from_orddict(orddict:from_list(List)).
> {4,
> {"gender","male",
> {"firstname","Igor",{"birthdate","02/15/1981",nil,nil},nil},
> {"lastname","Sucupira",nil,nil}}}
>
> 4> erlang:byte_size(term_to_binary(List)).
> 97
> 5> erlang:byte_size(term_to_binary(Dict)).
> 195
> 6> erlang:byte_size(term_to_binary(GB)).
> 125
>
> 8> timer:tc(lists, keysearch, ["firstname", 1, List]).
> {2,{value,{"firstname","Igor"}}}
> 9> timer:tc(gb_trees, lookup, ["firstname", GB]).
> {3,{value,"Igor"}}
> 10> timer:tc(dict, find, ["firstname", Dict]).
> {4,{ok,"Igor"}}
> 11> timer:tc(lists, keysearch, ["firstname", 1, List]).
> {3,{value,{"firstname","Igor"}}}
> 12> timer:tc(gb_trees, lookup, ["firstname", GB]).
> {3,{value,"Igor"}}
> 13> timer:tc(dict, find, ["firstname", Dict]).
> {4,{ok,"Igor"}}
These times are really too small to hope to show anything when
comparing them. You should run the tests 10k times for each one to get
some relevant figures.
How many columns do you think you will be using?
Robert
More information about the erlang-questions
mailing list