[erlang-questions] Benchmarking Erlang: Deathmatch of gb_trees, dict, ets, mnesia ... and registered names

Hynek Vychodil vychodil.hynek@REDACTED
Thu Oct 9 13:34:12 CEST 2008


Did you test if returned values from global:whereis_name  is correct? You
should do it especially when you don't believe benchmark result. You should
check return value from each function call if you want trust your code. It
can catch big amount of weird errors.

On Thu, Oct 9, 2008 at 1:14 PM, Joel Reymont <joelr1@REDACTED> wrote:

> %%% and finally, the moment you have all been waiting for!
> %%% ...
> %%% registered names
>
> -module(map7).
> -behaviour(gen_server).
>
> -export([init/1, handle_call/3, handle_cast/2,
>         handle_info/2, terminate/2, code_change/3]).
>
> -export([start/1, test/1, populate/1, lookup/1]).
>
> start(N) ->
>     gen_server:start({global, N}, map7, [], []).
>
> init([]) ->
>     {ok, none}.
>
> terminate(_, _) ->
>     ok.
>
> handle_cast(stop, Data) ->
>     {stop, normal, Data}.
>
> handle_call(Event, From, Data) ->
>      error_logger:info_report([{module, ?MODULE},
>                              {line, ?LINE},
>                              {self, self()},
>                                {event, Event},
>                               {from, From}
>                              ]),
>     {noreply, Data}.
>
> handle_info(Info, Data) ->
>     error_logger:info_report([{module, ?MODULE},
>                              {line, ?LINE},
>                              {self, self()},
>                              {message, Info}]),
>     {noreply, Data}.
>
> code_change(_, Data, _) ->
>     {ok, Data}.
>
> test(N) ->
>      {T1, _} = timer:tc(map7, populate, [N]),
>     {T2, _} = timer:tc(map7, lookup, [N]),
>      io:format("Populate: ~.4. f~n", [T1 / 1000000]),
>     io:format("Lookup:   ~.4. f~n", [T2 / 1000000]),
>      stop(N).
>
> populate(0) ->
>     ok;
>
> populate(N) ->
>     {ok, _} = start(N),
>     populate(N - 1).
>
> lookup(0) ->
>     ok;
>
> lookup(N) ->
>     P = global:whereis_name(N),
>     lookup(N - 1).
>
> stop(0) ->
>     ok;
>
> stop(N) ->
>     gen_server:cast({global, N}, stop),
>     stop(N - 1).
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>



-- 
--Hynek (Pichi) Vychodil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20081009/46d6938a/attachment.htm>


More information about the erlang-questions mailing list