Skip to content

@denen99 /gist:2582918
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
-module(test).
-export([start/0,load_data/1,run_select/0,run_foldl/0]).
-define(TAB,testets).
start() ->
load_ets_table(),
load_data(5000000),
io:format("Load data complete~n"),
{T,_} = timer:tc(?MODULE,run_select, []),
io:format("runselect took ~p seconds~n",[T/1000000]),
{T2,_} = timer:tc(?MODULE,run_foldl, []),
io:format("foldl took ~p seconds~n",[T2/1000000]).
load_data(0) ->
0;
load_data(N) ->
Key = "K" ++ N,
ets:insert(?TAB,{Key,N}),
load_data(N-1).
run_select() ->
lists:foreach(fun(X) ->
X end,
ets:select(?TAB,[{{'$1','$2'},[],['$$']}]) ).
run_foldl() ->
ets:foldl(fun({X,Y},_Acc) ->
X
end,
[], ?TAB).
load_ets_table() ->
case ets:info(?TAB,memory) of
undefined ->
ets:new(?TAB,[ordered_set,public, named_table]),
io:format("Table created~n");
_Any ->
ok
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.