dict slower than ets?

Wanglei flaboy.cn@REDACTED
Sun Aug 23 18:18:25 CEST 2009


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) ].
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090824/90403119/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.erl
Type: application/octet-stream
Size: 424 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090824/90403119/attachment.obj>


More information about the erlang-questions mailing list