[erlang-questions] dict slower than ets?

Colm Dougan colm.dougan@REDACTED
Mon Aug 24 01:16:33 CEST 2009


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
>


More information about the erlang-questions mailing list