diff options
-rw-r--r-- | Emakefile | 5 | ||||
-rwxr-xr-x | bench.erl | 90 | ||||
-rw-r--r-- | test/src/db.erl | 18 |
3 files changed, 89 insertions, 24 deletions
@@ -4,3 +4,8 @@ {i, "include/"}, {outdir, "ebin/"}, {parse_transform, lager_transform}]}. +{["test/src/*"], + [debug_info, + {i, "include/"}, + {outdir, "test/ebin/"}, + {parse_transform, lager_transform}]}. @@ -1,14 +1,36 @@ #!/usr/bin/env escript %% -*- erlang -*- +%%! -pa test/ebin -pa ../lager/ebin -pa ../lager/deps/goldrush/ebin add_entries(Entries) -> lists:foreach(fun (Entry) -> ht:add(Entry) end, Entries). +heapsize(Pid) when is_pid(Pid) -> + {total_heap_size, TotalHeapSize} = erlang:process_info(Pid, total_heap_size), + io_lib:format("~.2f M", [TotalHeapSize*8/1024/1024]); +heapsize(Name) when is_atom(Name) -> + heapsize(whereis(Name)). + +timeprint(Time) -> + io_lib:format("~.2fs", [Time/1000000]). + +printheapsize() -> + case false of + true -> + io:format("Heap size: local ~s ht ~s~n", [heapsize(self()), heapsize(ht)]); + false -> + none + end. + main(_) -> + %%eprof:start(), + lager:start(), + lager:set_loglevel(lager_console_backend, debug), FirstBatch = 5000000, - SecondBatch = 1000000, + SecondBatch = 5000000, + ThirdBatch = 1000000, LagerPath = "ebin", case code:add_path(LagerPath) of @@ -19,30 +41,50 @@ main(_) -> halt(1) end, ht:start_link(), - Entries = lists:map(fun (_) -> <<"bar">> end, lists:seq(1, FirstBatch)), - - io:format("Heap size: local ~p ht ~p~n", [erlang:process_info(self(), total_heap_size), erlang:process_info(whereis(ht), total_heap_size)]), - {Time1, Tree} = timer:tc(fun () -> ht:new(Entries) end), - io:format("Init with ~p entries: ~p~n", [length(Entries), Time1]), - io:format("Heap size: local ~p ht ~p~n", [erlang:process_info(self(), total_heap_size), erlang:process_info(whereis(ht), total_heap_size)]), - {Time2, {BuiltTree, _RootHash}} = timer:tc(fun () -> ht:root(Tree, length(Entries) - 1) end), - io:format("Build tree: ~p~n", [Time2]), - io:format("Heap size: local ~p ht ~p~n", [erlang:process_info(self(), total_heap_size), erlang:process_info(whereis(ht), total_heap_size)]), - {TimeChange, _} = timer:tc(fun () -> ht:change_tree(BuiltTree) end), - io:format("Change tree: ~p~n", [TimeChange]), - io:format("Heap size: local ~p ht ~p~n", [erlang:process_info(self(), total_heap_size), erlang:process_info(whereis(ht), total_heap_size)]), - {Time2b, _} = timer:tc(fun () -> ht:root() end), - io:format("Build tree: ~p~n", [Time2b]), - io:format("Heap size: local ~p ht ~p~n", [erlang:process_info(self(), total_heap_size), erlang:process_info(whereis(ht), total_heap_size)]), + + printheapsize(), + %%eprof:start_profiling([ht]), + {Time1, _Tree} = timer:tc(fun () -> ht:reset_tree([FirstBatch]) end), + %%eprof:stop_profiling(), + io:format("Init with ~p entries: ~s~n", [FirstBatch+1, timeprint(Time1)]), + printheapsize(), + + {Time2a, _} = timer:tc(fun () -> ht:root(FirstBatch div 2) end), + io:format("Build half tree: ~s~n", [timeprint(Time2a)]), + printheapsize(), + {Time2b, _} = timer:tc(fun () -> ht:root(FirstBatch - 10) end), + io:format("Build almost whole tree: ~s~n", [timeprint(Time2b)]), + printheapsize(), + {Time2c, _} = timer:tc(fun () -> ht:root() end), + io:format("Build whole tree: ~s~n", [timeprint(Time2c)]), + printheapsize(), + {Time2d, _} = timer:tc(fun () -> ht:root() end), + io:format("Build tree again: ~s~n", [timeprint(Time2d)]), + printheapsize(), io:format("treesize: ~p~n", [ht:size()]), - Entries2 = lists:map(fun (_) -> <<"bar">> end, lists:seq(1, SecondBatch)), - {Time3, _} = timer:tc(fun () -> add_entries(Entries2) end), - io:format("Add ~p entries ~p~n", [length(Entries2), Time3]), - io:format("Heap size: local ~p ht ~p~n", [erlang:process_info(self(), total_heap_size), erlang:process_info(whereis(ht), total_heap_size)]), - {Time4, _} = timer:tc(fun () -> ht:root() end), - io:format("Build tree: ~p~n", [Time4]), - io:format("Heap size: local ~p ht ~p~n", [erlang:process_info(self(), total_heap_size), erlang:process_info(whereis(ht), total_heap_size)]), + + {Time3, _} = timer:tc(fun () -> ht:load_tree(FirstBatch + SecondBatch) end), + io:format("Load up to ~p entries: ~s~n", [FirstBatch + SecondBatch + 1, timeprint(Time3)]), + printheapsize(), + + {Time4c, _} = timer:tc(fun () -> ht:root() end), + io:format("Build whole tree: ~s~n", [timeprint(Time4c)]), + printheapsize(), + {Time4d, _} = timer:tc(fun () -> ht:root() end), + io:format("Build tree again: ~s~n", [timeprint(Time4d)]), + printheapsize(), + io:format("treesize: ~p~n", [ht:size()]), + + + Entries2 = lists:map(fun (_) -> <<"bar">> end, lists:seq(1, ThirdBatch)), + {Time5, _} = timer:tc(fun () -> add_entries(Entries2) end), + io:format("Add ~p entries: ~s~n", [length(Entries2), timeprint(Time5)]), + printheapsize(), + {Time6, _} = timer:tc(fun () -> ht:root() end), + io:format("Build tree: ~s~n", [timeprint(Time6)]), + printheapsize(), garbage_collect(self()), garbage_collect(whereis(ht)), - io:format("Heap size: local ~p ht ~p~n", [erlang:process_info(self(), total_heap_size), erlang:process_info(whereis(ht), total_heap_size)]), + printheapsize(), + %%eprof:analyze(), ok. diff --git a/test/src/db.erl b/test/src/db.erl new file mode 100644 index 0000000..8c90842 --- /dev/null +++ b/test/src/db.erl @@ -0,0 +1,18 @@ +%%% Copyright (c) 2014, NORDUnet A/S. +%%% See LICENSE for licensing information. + +-module(db). +-export([get_by_indices/3]). + +get_by_indices(Start, _End, _Options) when Start < 0 -> + []; +get_by_indices(Start, End, _Options) -> + case Start =< End of + true -> + B = crypto:hash(sha256, <<"bar">>), + lists:map(fun (Index) -> + {Index, B, notfetched} + end, lists:seq(Start, End)); + false -> + [] + end. |