Skip to content

Instantly share code, notes, and snippets.

@akandratovich
Created May 6, 2012 12:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akandratovich/2621961 to your computer and use it in GitHub Desktop.
Save akandratovich/2621961 to your computer and use it in GitHub Desktop.
magic wtf
-module(qlct).
-compile([export_all]).
fill(T0, T1, []) -> {T0, T1};
fill(T0, T1, [H | T]) ->
ets:insert(T0, {H, make_ref()}),
ets:insert(T1, {H, make_ref()}),
fill(T0, T1, T).
table(N) ->
T0 = ets:new(ets, [ordered_set, private]),
T1 = ets:new(ets, [set, private]),
fill(T0, T1, lists:seq(0, N)).
i() ->
[{N, M, i(N, M)} || N <- [50000, 100000, 200000, 500000, 1000000, 2000000, 5000000],
M <- [1000, 10000, 20000, 49000]].
i(N, M) ->
{T0, T1} = table(N),
{Time0, _} = timer:tc(?MODULE, ets_select2, [T0, T0, 0, [], M]),
{Time1, _} = timer:tc(?MODULE, ets_select2, [T0, T1, 0, [], M]),
[ets:delete(T) || T <- [T0, T1]],
{Time0, Time1}.
ets_select2(_, _, _, Acc, 0) -> Acc;
ets_select2(T, T2, Key, Acc, N) ->
[V] = ets:lookup(T2, Key),
Key2 = ets:next(T, Key),
ets_select2(T, T2, Key2, [V | Acc], N - 1).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment