[erlang-questions] dict slower than ets?

Ngoc Dao ngocdaothanh@REDACTED
Mon Aug 24 02:41:22 CEST 2009


FYI: http://d.hatena.ne.jp/cooldaemon/20080722/1216706154

On my laptop:
benchmark:run(1000000).
--<process dictionary>--
set:210(302)ms
get:190(283)ms
--<dict>--
set:59430(62403)ms
get:790(841)ms
--<ets>--
set:1470(1566)ms
get:940(984)ms
--<gb_trees>--
set:10340(11286)ms
get:690(763)ms


On Mon, Aug 24, 2009 at 8:16 AM, Colm Dougan <colm.dougan@REDACTED> wrote:

> I'm pretty sure it would be expected that dict would be slower than
> ets for this use-case.  All the ets calls and data structures are
> implemented directly in C while the 'dict' modules uses pure erlang to
> emulate similar functionality.   If your keys are integers you could
> also look at the 'array' module which uses element/setelement under
> the hood rather than hashing.
>
> Colm
>
>
> On Sun, Aug 23, 2009 at 5:18 PM, Wanglei<flaboy.cn@REDACTED> wrote:
> > dict write x 10000
> >> {T,D} = timer:tc(test,dict_read,[]).
> > {86177,...
> > dict read x 10000
> >> timer:tc(test,dict_read,[D]).
> > {17260,
> > -----------------------------
> > ets write x 10000
> >> {T,E}=timer:tc(test,ets_write,[]).
> > {18005,20493}
> > dict read x 10000
> >> timer:tc(test,ets_read,[E]).
> > {15706,
> >
> > test.erl
> > ---------- 8< ------------------
> > -module(test).
> > -export([dict_write/0,dict_read/1,ets_write/0,ets_read/1]).
> > dict_write()->
> > D = dict:new(),
> > dict_write(D,10000).
> > dict_write(D,0)->D;
> > dict_write(D,N)->dict_write(dict:store(N,N,D),N-1).
> > dict_read(D)->
> > [ dict:find(X,D) || X<-lists:seq(0,10000) ].
> > ets_write()->
> > E = ets:new(test,[set]),
> > [ ets:insert(E,{X,X}) || X<-lists:seq(0,10000) ],
> > E.
> > ets_read(E)->
> > [ ets:lookup(E,X) || X<-lists:seq(0,10000) ].
> >
> >
> > ________________________________________________________________
> > erlang-questions mailing list. See http://www.erlang.org/faq.html
> > erlang-questions (at) erlang.org
> >
>
> ________________________________________________________________
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org
>
>


More information about the erlang-questions mailing list