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
_______________________________________________
erlang-questions mailing list
erlang-q...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions
On Jan 11, 2012, at 12:15 PM, Martin Dimitrov wrote:
> 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|...]
What's the reason behind this?
You can store binaries in ETS, you should also get significantly better results retrieving them.
--
AR
The question is actually about how to retrieve whole structures from
ETS. Binaries would be only referenced (as said in stackoverflow
thread).
100ms does not seem to be that much for copying 2MB of data from one
place in memory to another. Although for building such a list
cell-by-cell it seems pretty fast.
You can do the following:
- measure time to memcpy 2MB memory chunk in pure C or
- analyze how data is copied from ETS to process heap in the source code or
- wait for an answer from someone who knows it (OTP team)
Best,
Gleb
Best regards,
Martin
https://github.com/erlang/otp/blob/master/erts/emulator/beam/copy.c#L919
/Sverker, Erlang/OTP Ericsson
I assume it's copy_struct() in one direction (storing) and copy_shallow() in the other?
BR,
Ulf W
* As in, Björn G told me some 5-6 years ago, but I forgot the particulars.
/Sverker