Created
May 31, 2013 01:13
-
-
Save denen99/5682399 to your computer and use it in GitHub Desktop.
ETS Select quick test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(test). | |
-export([start/0,load_data/1,run_select/0,run_foldl/0]). | |
-define(TAB,testets). | |
start() -> | |
load_ets_table(), | |
load_data(100000), | |
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,[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