[erlang-questions] How fast is to retrieve date from ETS table

Martin Dimitrov mrtndimitrov@REDACTED
Wed Jan 11 12:15:30 CET 2012


I thought this is a lame question so I posted it on StackOverflow
(http://stackoverflow.com/questions/8811430/retrieval-of-data-from-ets-table)
so not to bother the list but there aren't many replies.

Here it is my observation:

I know that lookup time is constant for ETS tables. But I also heard
that the table is kept outside of the process and when retrieving data,
the data needs to be moved to the process heap. So, this is expensive.
But then, how to explain this:

1> {ok, B} = file:read_file("IMG_2171.JPG").
{ok,<<255,216,255,225,63,254,69,120,105,102,0,0,73,73,42,
      0,8,0,0,0,10,0,14,1,2,0,32,...>>}
2> size(B).
1986392
3> L = binary_to_list(B).
[255,216,255,225,63,254,69,120,105,102,0,0,73,73,42,0,8,0,0,
 0,10,0,14,1,2,0,32,0,0|...]
4> length(L).
1986392
5> ets:insert(utilo, {a, L}).
true
6> timer:tc(ets, match, [utilo, {a, '$1'}]).
{106000,
 [[[255,216,255,225,63,254,69,120,105,102,0,0,73,73,42,0,8,0,
    0,0,10,0,14,1,2|...]]]}

It takes 106000 microseconds to retrieve 1986392 long list which is
pretty fast, isn't it?
I also tried it from a module and the result is the same.

Best regards,

Martin





More information about the erlang-questions mailing list